Test instructions: There is an array, now to cut its size, the number of the same element in the array of the maximum value of the charm value of the group, the need to reduce the charm value can not be reduced, while minimizing the size to minimize
Analysis: Water problem, mainly do not want to complicate, there is a sinking heart to do
Code:
#include <iostream> #include <cstring> #include <algorithm> #define INF 1000000007#define Max (b) A >b?a:busing namespace Std;int n,a[100010];int tot[1000010];int l[1000010],r[1000010];int main () {while (cin>> N) {memset (tot,0,sizeof (tot)); memset (L,0,sizeof (L)); Memset (r,0,sizeof (r)); int mx=-1; for (int i=1;i<=n;i++) {cin >>a[i]; if (tot[a[i]]==0) l[a[i]]=i,r[a[i]]=i; else r[a[i]]=i; tot[a[i]]++; Mx=max (Mx,tot[a[i]); } int mi=inf; int ans; for (int i=1;i<=n;i++) {if (tot[a[i]]==mx) {int tmp=r[a[i]]-l[a[i]]; if (mi>tmp) {mi=tmp; ans=a[i];}}} cout<< l[ans]<< "" <<r[ans]<<endl;}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 558B AMR and the Large array-yy