zoukankan      html  css  js  c++  java
  • Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C

    题目链接:

    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
    ",ans[n]);
        }
        return 0;
    }
  • 相关阅读:
    MCU开发之I2C通信
    hibernate特殊的映射
    Hibernate使用
    css设置让a标签充满整个li
    margin
    border属性
    列表
    链接样式
    相机内参外参
    tmux
  • 原文地址:https://www.cnblogs.com/fenice/p/5535693.html
Copyright © 2011-2022 走看看