codeforces 673C
来源:互联网 发布:dna怎么入公安数据库 编辑:程序博客网 时间:2024/06/16 15:23
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.
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.
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
41 2 1 2
7 3 0 0
31 1 1
6 0 0
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.
已知一串数字,每种数字代表一种颜色,如果一个区间[i,j]中, ai颜色出现次数最多或者有和ai出现次数一样多的颜色但是颜色编号都比ai大,那么ai就是这个区间的领导颜色,统计各种颜色领导的区间数量。
模拟一下就好了
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<string>#include<vector>#include<stack>#include<set>#include<map>#include<queue>#include<algorithm>using namespace std;int ball[5005],coun[5005],col[5005];int main(){int i,j;int cal=0;int n;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d",&ball[i]);}int len;int tmp;int max=0;for(i=1;i<=n;i++){max=0;col[ball[i]]++;coun[ball[i]]++;if(max<coun[ball[i]]){max=coun[ball[i]];tmp=ball[i];}for(j=i+1;j<=n;j++){coun[ball[j]]++;if(max<coun[ball[j]]){max=coun[ball[j]];tmp=ball[j];}else if(max==coun[ball[j]]){if(tmp>ball[j]){tmp=ball[j];}}col[tmp]++;}memset(coun,0,sizeof(coun));}for(i=1;i<=n;i++){printf("%d",col[i]);if(i!=n)printf(" ");}printf("\n"); return 0;}
- CodeForces 673C
- codeforces 673c[补]
- codeforces 673C
- codeforces 673C(思维)
- CodeForces 673C Bear and Colors
- CodeForces 673C - Bear and Colors(模拟)
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- codeforces 148 div2 C
- codeforces 242C
- Codeforces-234C Weather
- Activity跳转(装备选择案例)
- 如何过滤MAP中的特殊字符
- 前向分布算法
- nyoj 1238 最少换乘(spfa)
- HBase的配置
- codeforces 673C
- HAUTOJ 1265
- Java 套接字
- 使用Eclipse+scala计算Pi
- [机器学习]Logistic回归梯度上升法与改进的随机梯度上升算法
- 错误: 找不到或无法加载主类
- Android Greendao3.0框架的使用
- centos 6.5配置epel源
- SDN實驗(一) Mininet使用