Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors

题目链接:

http://codeforces.com/contest/673/problem/C

题解:

枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了。

暴力n*n.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

const int maxn=5555;
const int INF=0x3f3f3f3f;

int arr[maxn],ans[maxn],cnt[maxn];

int main() {
    int n;
    while(scanf("%d",&n)==1&&n) {
        memset(ans,0,sizeof(ans));
        for(int i=1; i<=n; i++) {
            scanf("%d",&arr[i]);
        }
        for(int st=1;st<=n;st++){
            memset(cnt,0,sizeof(cnt));
            int ma=-1,tmp=INF;
            for(int ed=st;ed<=n;ed++){
                cnt[arr[ed]]++;
                if(cnt[arr[ed]]>ma){
                    ma=cnt[arr[ed]]; tmp=arr[ed];
                }else if(cnt[arr[ed]]==ma){
                    tmp=min(tmp,arr[ed]);
                }
                ans[tmp]++;
            }
        }
        for(int i=1;i<n;i++){
            printf("%d ",ans[i]);
        }
        printf("%d\n",ans[n]);
    }
    return 0;
}

 

posted @ 2016-05-27 18:36  fenicnn  阅读(140)  评论(0)    收藏  举报