题目链接:

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.

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.

题意:

给出这么多颜色,在一个序列中,dominant是出现次数最多的数,如果出现次数最多的不止一个,那么就是数值最小的那个;

思路

暴力跑出[i,j]中每个数出现的次数,同时更新这里面的的dominant;

AC代码

#include <bits/stdc++.h>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e5+;
int n,flag[][],a[],ans[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<=n;i++)
{
int num=,temp;
for(int j=i;j<=n;j++)
{
flag[i][a[j]]++;
if(flag[i][a[j]]>num)
{
num=flag[i][a[j]];
temp=a[j];
}
else if(flag[i][a[j]]==num)
{
if(a[j]<temp)
{
temp=a[j];
}
}
ans[temp]++;
} }
for(int i=;i<=n;i++)
{
printf("%d ",ans[i]);
} return ;
}

codeforces 673C C. Bear and Colors(暴力)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. C. Bear and Colors

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

  4. Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力

    D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n citie ...

  5. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors

    题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...

  6. [Codeforces673C]Bear and Colors(枚举,暴力)

    题目链接:http://codeforces.com/contest/673/problem/C 题意:给一串数,不同大小的区间内出现次数最多的那个数在计数的时候会+1,问所有区间都这样计一次数,所有 ...

  7. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) C. Bear and Up-Down 暴力

    C. Bear and Up-Down 题目连接: http://www.codeforces.com/contest/653/problem/C Description The life goes ...

  8. Codeforces Gym 100513M M. Variable Shadowing 暴力

    M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...

  9. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

随机推荐

  1. 深入V8引擎-Time核心方法之mac篇

    由于底层逻辑实现不同操作系统区别很大,所以干脆分篇来说. 主要讲一下Time.TimeTicks两个类里面对于时间戳的实现,其余的运算符重载.边缘工具方法就不看了,先是Time. Time 类本身的说 ...

  2. TOT 傅立叶变换 FFT 入门

    HDU 1402,计算很大的两个数相乘. FFT 只要78ms,这里: 一些FFT 入门资料:http://wenku.baidu.com/view/8bfb0bd476a20029bd642d85. ...

  3. 面试题:oracle数据库行转列的问题

    今天我一个学弟问了一个面试题: 有表A,结构如下:A: p_ID p_Num s_id1 10 011 12 022 8 013 11 013 8 03其中:p_ID为产品ID,p_Num为产品库存量 ...

  4. java 基础 5 String StringBuffer StringBuilder

    String是不可变的,原因 1是可以缓存hash值,因为String的hash值经常被使用,例如String用作HashMap等.不可变特性  使得hash值不变,因此只需要进行一次计算: 2Str ...

  5. go语言学习之路 一:开发环境配置

    1. 安装go 1)下载地址:http://www.golangtc.com/download,下载后直接双击msi文件安装,默认安装在c:\go 2)安装完成后默认会在环境变量 Path 后添加 G ...

  6. mac mysql重置密码

    http://blog.csdn.net/xiaozhuanddapang/article/details/53185775 情况一:在mysql官网直接下载dmg文件进行安装,忘记密码 1.关闭my ...

  7. 第二讲_图像数据处理Image Data Processing

    第二讲_图像数据处理Image Data Processing 深度模型出现后被弱化,但是思想的影子在深度模型中可以看到的 图片存储原理 RGB颜色空间:三通道(b,g,r),加法混色 CMY(K): ...

  8. linux系统(ubuntu14.04)安装mentohust完毕校园网锐捷认证

    近来升级电脑又一次做了系统.再次面临这linux系统下的各种校园网上网限制. 我在这里採用了mentohust来完毕锐捷认证. 这里我们选择Mentohust取代锐捷. Mentohust 是由华中科 ...

  9. onlyOffice 开发相关 总结

    onlyOffice 服务端 客户端 相关开发整理 功能: 所有客户端都可用 云端部署服务 查看 预览 doc ppt excel 编辑 权限控制 开发技术准备 用户服务器端 提供保存接口 用户浏览器 ...

  10. HDOJ 1217 Arbitrage(拟最短路,floyd算法)

    Arbitrage Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...