codeforces 351 div2 C. Bear and Colors 暴力
2 seconds
256 megabytes
standard input
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.
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.
- 4
1 2 1 2
- 7 3 0 0
- 3
1 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.
题意:找出每个区间的重数,将重数的次数输出;
思路:暴力找复杂度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 = , ch ;
- while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
- {
- if( ch == EOF ) return << ;
- }
- res = ch - '' ;
- while( ( ch = getchar() ) >= '' && ch <= '' )
- res = res * + ( ch - '' ) ;
- return res ;
- }
- int a[];
- int flag[];
- int ans[];
- int main()
- {
- int x,y,z,i,t;
- scanf("%d",&x);
- for(i=;i<=x;i++)
- scanf("%d",&a[i]);
- for(i=;i<=x;i++)
- {
- memset(flag,,sizeof(flag));
- int maxx=,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=;i<=x;i++)
- printf("%d ",ans[i]);
- return ;
- }
codeforces 351 div2 C. Bear and Colors 暴力的更多相关文章
- 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 ...
- codeforces 673C C. Bear and Colors(暴力)
题目链接: C. Bear and Colors time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces#543 div2 B. Mike and Children(暴力?)
题目链接:http://codeforces.com/problemset/problem/1121/B 题意 给n个数 最多的对数 其中每一对(i,j)的ai+aj都相等(不知道怎么解释.... 判 ...
- codeforces 356 div2 C.Bear and Prime 100 数学
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...
- codeforces 9 div2 C.Hexadecimal's Numbers 暴力打表
C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- C. Bear and Colors
C. Bear and Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
随机推荐
- Python中如何获取类属性的列表
这篇文章主要给大家介绍了在Python中如何获取类属性的列表,文中通过示例代码介绍的很详细,相信对大家的学习或者工作具有一定的参考借鉴价值,有需要的朋友可以参考借鉴,下面来一起看看吧. 前言 最近工作 ...
- HTML <input> <button> <submit>
定义和用法 value 属性规定与按钮关联的初始值.请始终为按钮规定 type 属性,如果不填默认值是 "submit".submit其实就是一个特殊的button. <bu ...
- CloudFlare CDN折腾记-优化设置
近期又在折腾了,常访问我博客的朋友或许页面曾出现过502错误提示,那是折腾CloudFlare CDN不成功的提示.在此先感谢坛子,在他的执着和求真之下,昨天晚上终于成功使用上CloudFlare C ...
- linux mail 发送邮件附件
在很多场景中我们会使用Shell命令来发送邮件,而且我们还可能在邮件里面添加附件,本文将介绍使用Shell命令发送带附件邮件的几种方式,希望对大家有所帮助. 文章目录 1 使用mail命令 2 使用m ...
- 评价指标的局限性、ROC曲线、余弦距离、A/B测试、模型评估的方法、超参数调优、过拟合与欠拟合
1.评价指标的局限性 问题1 准确性的局限性 准确率是分类问题中最简单也是最直观的评价指标,但存在明显的缺陷.比如,当负样本占99%时,分类器把所有样本都预测为负样本也可以获得99%的准确率.所以,当 ...
- jxl(Java Excel API) 使用方法 【1】
// 构建Workbook对象, 只读Workbook对象 // 直接从本地文档创建Workbook // 从输入流创建Workbook Workbook workbook = nul ...
- sql 中延时操作
select 1; WAITFOR DELAY '00:00:30'; select 2; --执行完第一个之后会 延时 30秒,才会执行第二个sql
- SV中的Interface和Program
Interface:SV中新定义的接口方式,用来简化接口连接,使用时注意在module或program之外定义interface,然后通过'include来添加进工程. interface arb_ ...
- Hive sql和Presto sql的一些对比
最近由于工作上和生活上的一些事儿好久没来博客园了,但是写博客的习惯还是得坚持,新的一年需要更加努力,困知勉行,终身学习,每天都保持空杯心态.废话不说,写一些最近使用到的Presto SQL和Hive ...
- python练习题,写一个方法 传进去列表和预期的value 求出所有变量得取值可能性(例如list为[1,2,3,4,5,6,12,19],value为20,结果是19+1==20只有一种可能性),要求时间复杂度为O(n)
题目:(来自光荣之路老师)a+b==valuea+b+c=valuea+b+c+d==valuea+b+c+d+...=valuea和b....取值范围都在0-value写一个方法 传进去列表和预期得 ...