Codeforces 558B. AMR and the Large Array problem Solving report

Source: Internet
Author: User

Title Link: Http://codeforces.com/problemset/problem/558/B

Title meaning: Give a sequence, and then find the most occurrences, but the interval occupies the shortest interval around the value.

Because it is a side-read-in-edge comparison, the most critical issue is to record where each number first appears, that is, the left value. Because you want to ensure that the number of occurrences is the most, you need a cnt[] array to record the number of occurrences. Then, when the maximum number of occurrences is the same as the current cnt[x], select a shorter interval and then update the left and right interval values.

The short circuit in the game unexpectedly can't come out ~ ~ ~ Tears ~ ~ Tears->_<

  

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <algorithm>6 using namespacestd;7 8 Const intMAXN = 1e6 +5;9 intCNT[MAXN];Ten intPL[MAXN];//record where each number first appears One  A intMain () - { - #ifndef Online_judge theFreopen ("In.txt","R", stdin); -     #endif //Online_judge -  -     intN, A; +      while(SCANF ("%d", &n)! =EOF) { -memset (CNT,0,sizeof(CNT)); +memset (PL,0,sizeof(PL)); A         intmax_cnt =0; at         intMin_dis =0; -         intL =0, r =0; -  -          for(inti =0; I < n; i++) { -scanf"%d", &a); -  in             if(!Cnt[a]) { -Pl[a] =i; to             } +cnt[a]++; -  the             if(Max_cnt <Cnt[a]) { *max_cnt =Cnt[a]; $L = Pl[a], r =i;Panax NotoginsengMin_dis = i-tl; -             } the             if(max_cnt = = Cnt[a] && I-pl[a] <Min_dis) { +Min_dis = i-Pl[a]; AL =Pl[a]; theR =i; +             } -         } $printf"%d%d\n", L +1, r+1); $     } -     return 0; -}

Codeforces 558B. AMR and the Large Array problem Solving report

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.