Codeforces 558B AMR and the Large Array

Source: Internet
Author: User

This b is not difficult ... It's mostly test instructions and details.

Test instructions is to find the most occurrences of the number of the left and right end of the value,, as many words to find the smallest interval,,, the same length of the left to find ...

Change a little bit messy,,,, slowly change well,,,,,

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace Std;
struct node
{
int c,b;
}A[100001];

int cmp (const void *a,const void *b)
{
struct node *q= (node*) A;
struct node *w= (node*) b;
if (q->c!=w->c) return q->c-w->c;
else return q->b-w->b;
}

int main ()
{
int m;
scanf ("%d", &m);
int i;
for (i=0;i<m;i++)
{
scanf ("%d", &a[i].c);
A[i].b=i;
}
Qsort (A,m,sizeof (a[0]), CMP);
for (i=0;i<10;i++) printf ("%d*\n", a[i].b);
int Ans=1;
int ans1=a[0].b;
int ans2=a[0].b;
int left=a[0].b,right=a[0].b;
printf ("%d%d**\n", ans1,ans2);
int w=1;
for (i=1;i<m;i++)
{
if (A[I].C==A[I-1].C)
{
w++;
if (i==m-1)
{
right=a[i].b;
if (W>ans) {ans=w; ans1=right; ans2=left;}
if (W==ans)
{

if (RIGHT-LEFT&LT;ANS1-ANS2) ans1=right,ans2=left;
}
}
}
Else
{
printf ("%d**\n", I);
printf ("%d**\n", W);
right=a[i-1].b;
if (W>ans) {ans=w; ans1=right; ans2=left;}
printf ("%d**%d\n", ans1,ans2);
if (W==ans)
{
if (RIGHT-LEFT&LT;ANS1-ANS2) ans1=right,ans2=left;
else if (RIGHT-LEFT==ANS1-ANS2)
{
if (ans2>left) ans1=right,ans2=left;
}
}
left=a[i].b;
W=1;
}
}
printf ("%d%d\n", ans2+1,ans1+1);

return 0;
}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 558B AMR and the Large Array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.