【Codeforces Round #351 Div. 2】 673C Bear and Colors

原创 2016年08月28日 21:40:05

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.


【题目分析】
很显然有接近n^2个区间,直接暴力就是n^3的复杂度会爆炸,不妨固定一个左端点l然后r扫描过去,这样就可以做到n^2的复杂度了。


【代码】

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n,col[5010],time[5010],tong[5010],maxv,maxn;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%d",&col[i]);
    for (int i=1;i<=n;++i){
        memset(tong,0,sizeof tong);
        maxv=0;maxn=99999;
        for (int j=i;j<=n;++j){
            tong[col[j]]++;
            if (tong[col[j]]>maxv){
                maxv=tong[col[j]];
                maxn=col[j];
            }
            else if(tong[col[j]]==maxv&&maxn>col[j])
            {
                maxv=tong[col[j]];
                maxn=col[j];
            }
            time[maxn]++;
        }
    }
    for (int i=1;i<n;++i)
      printf("%d ",time[i]);
    printf("%d\n",time[n]);
    return 0;
}
版权声明:标注来源之后可随意引用[请记得添加友链]

相关文章推荐

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths

D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces 673C Bear and Colors【暴力枚举】

C. Bear and Colors time limit per test 2 seconds memory limit per test 256 megabytes inpu...

Codeforces673C Bear and Colors(枚举区间)

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

Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers(暴力)

题目链接:点击打开链接 题意:给n个数, m次询问, 每次询问时一个区间[l, r]。 求这个区间中的所有素数,能被n个数中的几个数整除的累加和。 思路:没想到什么好办法, 直接筛出素数以后直接暴...

Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers

C. Bear and Prime Numbers time limit per test 2 seconds memory limit per test 512 megabytes in...

Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers(素数筛法)

Recently, the bear started studying data structures and faced the following problem. You are given ...

Codeforces Round #356 (Div. 2) C. Bear and Prime 100 (有趣的题目)

C. Bear and Prime 100time limit per test 1 second memory limit per test 256 megabytes input sta...

Codeforces Round #356 (Div. 2)-C. Bear and Prime 100

Codeforces Round #356 (Div. 2)-C. Bear and Prime 100

Codeforces Round #226 (Div. 2)--C. Bear and Prime Numbers

C. Bear and Prime Numbers time limit per test 2 seconds memory limit per test 512 megaby...

Codeforces Round #356 (Div. 2)-A. Bear and Five Cards(模拟)

A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)