zoukankan      html  css  js  c++  java
  • codeforces 351 div2 C. Bear and Colors 暴力

    C. Bear and Colors
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.

    For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.

    There are  non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.

    The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.

    Output

    Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.

    Examples
    input
    4
    1 2 1 2
    output
    7 3 0 0 
    input
    3
    1 1 1
    output
    6 0 0 
    Note

    In the first sample, color 2 is dominant in three intervals:

    • An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
    • An interval [4, 4] contains one ball, with color 2 again.
    • An interval [2, 4] contains two balls of color 2 and one ball of color 1.

    There are 7 more intervals and color 1 is dominant in all of them.

     题意:找出每个区间的重数,将重数的次数输出;

    思路:暴力找复杂度o(n*n)

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define inf 999999999
    //#pragma comment(linker, "/STACK:102400000,102400000")
    int scan()
    {
        int res = 0 , ch ;
        while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
        {
            if( ch == EOF ) return 1 << 30 ;
        }
        res = ch - '0' ;
        while( ( ch = getchar() ) >= '0' && ch <= '9' )
            res = res * 10 + ( ch - '0' ) ;
        return res ;
    }
    int a[5010];
    int flag[5010];
    int ans[5010];
    int main()
    {
        int x,y,z,i,t;
        scanf("%d",&x);
        for(i=1;i<=x;i++)
        scanf("%d",&a[i]);
        for(i=1;i<=x;i++)
        {
            memset(flag,0,sizeof(flag));
            int maxx=0,ji;
            for(t=i;t<=x;t++)
            {
                //cout<<maxx<<" "<<ji<<" "<<a[t]<<endl;
                flag[a[t]]++;
                if(flag[a[t]]>maxx)
                {
                    maxx=flag[a[t]];
                    ji=a[t];
                    ans[ji]++;
                }
                else if(flag[a[t]]==maxx&&ji>a[t])
                {
                    ji=a[t];
                    ans[ji]++;
                }
                else
                ans[ji]++;
            }
        }
        for(i=1;i<=x;i++)
        printf("%d ",ans[i]);
        return 0;
    }
  • 相关阅读:
    VS提示“项目文件" "已被重命名或已不在解决方案中”的解决办法 .
    微信公众平台教程和SDK收集
    “SQLServerAgent当前未运行”问题解决
    $(document).click() 在苹果手机上不能正常运行
    友盟iOS推送配置(从真机调试到推送)
    Ubuntu安装VMware Tools的方法
    TortoiseSVN客户端如何更改新的URL
    Windows Server 2008系统如何取消登录时要按Ctrl+Alt+Delete组合键
    Windows Server 2008 显示桌面图标
    用WinRAR进行安装包的制作
  • 原文地址:https://www.cnblogs.com/jhz033/p/5474183.html
Copyright © 2011-2022 走看看