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

    C. Bear and Colors

    题目连接:

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

    Description

    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.

    Sample Input

    4
    1 2 1 2

    Sample Output

    7 3 0 0

    题意

    有n个数,然后对于每个区间,这个区间的特征等于这个区间出现次数最多的数,如果有两个数出现的次数一样的话,那么就取较小的那个数

    现在问你每个数当了多少次特征

    题解:

    n才5000,直接n^2枚举就好了,不要犹豫……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 5005;
    int n,a[maxn],ans[maxn];
    int H[maxn];
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        for(int i=1;i<=n;i++)
        {
            memset(H,0,sizeof(H));
            int ans1=0,ans2=0;
            for(int j=i;j<=n;j++)
            {
                H[a[j]]++;
                if(ans1<H[a[j]]||(ans1==H[a[j]]&&a[j]<ans2))
                {
                    ans1=H[a[j]];
                    ans2=a[j];
    
                }
                ans[ans2]++;
            }
        }
        for(int i=1;i<=n;i++)
            printf("%d ",ans[i]);
        printf("
    ");
    }
  • 相关阅读:
    Java中的几种常用循环 for switch while dowhile
    HTML的各种基本标签
    2017年终总结
    HTML C# ajax结合ashx处理程序实现文件上传
    HTML div鼠标悬停控制子控件显示与隐藏
    HTML 使用CSS 如何去掉文本聚焦框
    HTML input 文本框如何添加提示信息
    CSS 如何通过top left 定位控制div在另一个div的位置
    CSS background 属性
    php支付接口开发-支付宝-开发前期准备
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5469758.html
Copyright © 2011-2022 走看看