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 ...
随机推荐
- excel 使用
列于列拼接
- SQL分类之DDL:操作数据库表
DDL:操作数据库表 1.操作数据库:CRUD 1.C(Create):创建 创建数据库: create database 数据库名称 创建数据库,判断不存在,再创建: create database ...
- - XML 解析 总结 DOM SAX PULL MD
目录 目录 XML 解析 总结 DOM SAX PULL MD 几种解析方式简介 要解析的内容 DOM 解析 代码 输出 SAX 解析 代码 输出 JDOM 解析 代码 输出 DOM4J 解析 代码 ...
- 简单实现python调用c#dll动态链接库
在python调用c#dll库时要先安装库clr,即安装pythonnet,参考文章:https://www.cnblogs.com/kevin-Y/p/10235125.html(为在python中 ...
- winform实现Session功能(保存用户信息)
问题描述:在winform中想实现像BS中类似Session的功能,放上需要的信息,在程序中都可以访问到. 解决方案:由于自己很长时间没有做过winform的程序,一时间竟然手足无措起来.后来发现wi ...
- javascript原型深入解析2--Object和Function,先有鸡先有蛋
1.提出两个问题: Js 的prototype和__proto__ 是咋回事? 先有function 还是先有object? 2.引用<JavaScript权威指南>的一段描述: 每个JS ...
- [Linux] Ubuntu Server18 python3.7 虚拟环境
Ubuntu Server18 python3.7 环境 Ubuntu Server18 默认是python3.6, 目前开发主要用python3.7. 所以想搭建python3.7环境. 试过几手动 ...
- django配置文件
1.BASSE_DIR BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 当前工程的根目录,Django会依 ...
- renren-fast后端源码参考-配置和对应工具
1. renren-fast后端源码参考-配置和对应工具 1.1. 前言 renren-fast是个开源的前后端分离快速开放平台,没有自己框架的同学可以直接使用它的,而我打算浏览一遍它的代码,提取一些 ...
- jQuery(五): Deferred
jQuery(五): Deferred 有啥用 通常来说,js请求数据,无论是异步还是同步,都不会立即获取到结果,通常而言,我们一般是是使用回调函数再执行,而 deferred就是解决jQuery的回 ...