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)-(前缀和 + 模拟)的更多相关文章

  1. Codeforces Round #558 (Div. 2)C(计算几何,排列组合,模拟)

    #include<bits/stdc++.h>using namespace std;typedef struct{ double k,b;}node;node k[1000007];bo ...

  2. Codeforces Round #558 (Div. 2)

    目录 Codeforces Round #558 (Div. 2) 题解 A Eating Soup B Cat Party C Power Transmission D Mysterious Cod ...

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

  4. Codeforces Round #558 (Div. 2)B(SET,模拟)

    #include<bits/stdc++.h>using namespace std;int a[100007];int cnt[100007];int main(){    int n; ...

  5. Codeforces Round 558(Div 2)题解

    这场比赛没有打,后来和同学们一起开了场镜像打…… B是SB题结果WA了5发…… C是SB题结果差5min调出……虽然中间有个老师讲题吃掉了1h D是比较神仙的题(2200),但是做出来了?算是比较超常 ...

  6. Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)

    题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...

  7. Codeforces Round #336 (Div. 2)B. Hamming Distance Sum 前缀和

    B. Hamming Distance Sum 题目连接: http://www.codeforces.com/contest/608/problem/A Description Genos need ...

  8. Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)

    题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...

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

随机推荐

  1. xunsearch搜索测试

    1.导入测试数据 cd $prefix/sdk/php util/Indexer.php --source=csv --clean demo 然后出现 初始化数据源 ... csv WARNING: ...

  2. 029 ElasticSearch----全文检索技术04---基础知识详解02-查询

    1.查询 (1)基本查询 基本语法: GET /索引库名/_search { "query":{ "查询类型":{ "查询条件":" ...

  3. Ubuntu 18 Kubernetes集群的安装和部署 以及Helm的安装

    首先说一下我的环境, 我是在windows 10 上面建了一个ubuntu18的虚拟机,同时由于某些原因 不受网络限制, 所以安装比较顺利. Install 1.安装并启用 Docker  sudo ...

  4. sqlalchemy 配合bootstrap-table实现后台分页

    创建公共的mysql连接函数 def db_session(): db_config='mysql+mysqldb://'+ mysqluser + ':' + mysqlpassword+'@'+m ...

  5. DevExpress之GridControl控件小知识

    DevExpress之GridControl控件小知识 一.当代码中的DataTable中有建数据关系时,DevExpress 的 GridControl 会自动增加一个子视图 .列名也就是子表的字段 ...

  6. mybatis使用用stdout-logging日志显示sql语句

    在开发中,我们很多时候需要知道当前执行的sql语句是什么样的,但是默认mybatis是不显示sql的,此时我们就可以使用stdout-logging了.1.创建mybatis-config.xml文件 ...

  7. Kafka分布式的消息顺序

    Kafka分布式的单位是partition,同一个partition用一个write ahead log组织,所以可以保证FIFO的顺序.不同partition之间不能保证顺序. 但是绝大多数用户都可 ...

  8. 米尔XC7Z010开发板资源

    关于XC7Z010开发板 详细介绍http://www.myir-tech.com/product/myc_C7Z010_20.htm Xilinx基于28nm工艺流程的Zynq-7000 All P ...

  9. Vue笔记目录

    Vue笔记目录 一.Vue.js介绍 二.vue基础-vue-cli(vue脚手架) ...持续更新中,敬请期待

  10. FreeRTOS 任务通知模拟计数型信号量

    举例 //释放计数型信号量任务函数 void SemapGive_task(void *pvParameters) { u8 key; while(1) { key = KEY_Scan(0); // ...