Codeforces Round #558 (Div. 2)-Cat Party (Hard Edition)-(前缀和 + 模拟)
http://codeforces.com/problemset/problem/1163/B2
题意:有n天,每天有一个颜色,截取前x天,随便抽掉一天,使剩下的各个颜色出现的次数相等。
解题,也可以解决B1:
有三种情况:
1.一种颜色出项一次,其他相等,抽掉出现1次颜色的那一天,例如13天分别是
6 222 333 444 555
2.只有两种颜色次数,次数相差1,并且最大出现次数的颜色只有1次,例如13天分别是
777 333 222 8888
3.所有颜色都只出现过1次,例如
1 2 3 4 5 6 7 8 9
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<map>
#include<cstring>
#include<set>
#include<queue>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std; int a[];///每一天的颜色
int color[];///下标颜色出现的次数
int n; int main()///cf558div2B
{
while(scanf("%d",&n)!=EOF)
{
memset(a,,sizeof(a));
memset(color,,sizeof(color));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
int sum=;/// 一共出现几种颜色
int maxx=-,ans=;///最大次数 答案
int one=; ///特判颜色次数为1的颜色数量
set<int>se;///判断当前颜色是否出现过
map<int,int>mp;///快速找到最大次数的颜色数
for(int i=;i<=n;i++)
{
if( !se.count(a[i]) )
{
sum++;
se.insert(a[i]);
}
color[ a[i] ]++;
mp[ color[ a[i] ] ]++;///每一次都累加,最后只需要用到maxx和maxx-1 if( color[ a[i] ]== )
one++;
else if( color[ a[i] ]== )///颜色出现的次数超过1自然会先变成2,并且回不来了
one--; if( color[ a[i] ] > maxx )
maxx=color[ a[i] ]; if( mp[maxx]== && mp[maxx-]==sum )
ans=i;
if( mp[maxx]==sum- && one== )
ans=i;
if(maxx== && mp[maxx]==sum)
ans=i;
}
printf("%d\n",ans);
}
return ;
}
Codeforces Round #558 (Div. 2)-Cat Party (Hard Edition)-(前缀和 + 模拟)的更多相关文章
- Codeforces Round #558 (Div. 2)C(计算几何,排列组合,模拟)
#include<bits/stdc++.h>using namespace std;typedef struct{ double k,b;}node;node k[1000007];bo ...
- Codeforces Round #558 (Div. 2)
目录 Codeforces Round #558 (Div. 2) 题解 A Eating Soup B Cat Party C Power Transmission D Mysterious Cod ...
- Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和
Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #558 (Div. 2)B(SET,模拟)
#include<bits/stdc++.h>using namespace std;int a[100007];int cnt[100007];int main(){ int n; ...
- Codeforces Round 558(Div 2)题解
这场比赛没有打,后来和同学们一起开了场镜像打…… B是SB题结果WA了5发…… C是SB题结果差5min调出……虽然中间有个老师讲题吃掉了1h D是比较神仙的题(2200),但是做出来了?算是比较超常 ...
- Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)
题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...
- Codeforces Round #336 (Div. 2)B. Hamming Distance Sum 前缀和
B. Hamming Distance Sum 题目连接: http://www.codeforces.com/contest/608/problem/A Description Genos need ...
- Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)
题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...
- Codeforces Round #325 (Div. 2) B. Laurenty and Shop 前缀和
B. Laurenty and Shop Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/p ...
随机推荐
- [转帖]关于 ./configure
./configure --prefix=/usr/local/scws --prefix选项是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr/local/bin,库文件默认放在/ ...
- [转帖]kafka 如何保证数据不丢失
kafka 如何保证数据不丢失 https://www.cnblogs.com/MrRightZhao/p/11498952.html 一般我们在用到这种消息中件的时候,肯定会考虑要怎样才能保证数 ...
- Oulipo 子串查找
题目描述 思路 使用哈希值表示较长串的子串的值,直接比较哈希值是否相等 代码 #include <cstdio> #include <cstring> using namesp ...
- C语言中字符型,整数型,浮点型在内存中如何存储
···void main() { unsigned char a = 97; printf("%p",&a); printf("%c,%d\n", a, ...
- NodeJS安装及部署(Linux系统)
环境说明:Linux环境,CentOS 7版本. 第一步:下载node地址:https://nodejs.org/en/download/ 下载后,是一个[node-v10.16.0-linux-x6 ...
- AGC035
Contest Page A 唯一会做的题/kk 题目相当于要求相邻三个的异或和为\(0\). 当我们放入了三个数\(a,b,c\)时,接下来的放入顺序显然一定是\(a,b,c,a,b,c,...\) ...
- 在vps上搭建hexo博客
最近更换了服务器,需要把自己的Hexo Next重新部署到新服务器上,本文记录一下在vps上搭建hexo博客的过程. 在vps上搭建hexo博客需要下面这些工具: Nginx: 用于博客展示 SSH: ...
- .net core使用ocelot---第二篇 身份验证
简介原文链接 .net core使用ocelot---第一篇 简单使用 接上文,我将继续介绍使用asp.net core 创建API网关,主要介绍身份验证(authentication )相 ...
- easydict的使用方法
easydict的作用:可以使得以属性的方式去访问字典的值 from easydict import EasyDict as edict a=['8',2,3]a=edict()a.f=99print ...
- 【WEB基础】HTML & CSS 基础入门(10)布局与定位
块级元素和行内元素 HTML里的元素可以分为块级元素和行内元素两大类: