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. Qt SDK Issue cstdlib: fatal error: stdlib.h: No such file or directory

    *To reproduce the issue, I've tried the following solutions which did not help:* *1) Globally remove ...

  2. 第十二节:Asp.Net Core 之分布式缓存(SQLServer和Redis)

    一. 整体说明 1. 说明 分布式缓存通常是指在多个应用程序服务器的架构下,作为他们共享的外部服务共享缓存,常用的有SQLServer.Redis.NCache.     特别说明一下:这里的分布式是 ...

  3. 使用Fiddler抓包、wireshark抓包分析(三次握手、四次挥手深入理解)

    ==================Fiddler抓包================== Fiddler支持代理的功能,也就是说你所有的http请求都可以通过它来转发,Fiddler代理默认使用端口 ...

  4. Scala Class etc. 2

    Higher-Order Functions def 定义的是方法,而不是函数 函数可作为变量存在,可直接调用,也可作为值传递给其他函数 _ 后缀将普通方法变为函数: ceil _ 根据上下文编译器可 ...

  5. MyBatis-Plus入门Demo详解

    一.简介: 引用官方文档(本文主要参考官方文档示例): MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发.提高效率而生 ...

  6. Wamp Https 的 SSL认证 配置说明

    Wamp Https 的 SSL认证 配置说明版本 Apache2.2.11注:右下角图标的 重启 不能有效加载 配置文件 应退出后重新运行注:C:\wamp\bin\apache\Apache2.2 ...

  7. Prometheus监控学习笔记之容器监控Grafana模块

    0x00 概述 Grafana 是一个开源的,可以用于大规模指标数据的可视化项目,甚至还能对指标进行报警.基于友好的 Apache License 2.0 开源协议,目前是prometheus监控展示 ...

  8. ASP.NET Core中app.UseDeveloperExceptionPage和app.UseExceptionHandler方法有什么用

    在新建一个ASP.NET Core项目后,在项目Startup类的Configure方法中默认会添加两个方法的调用,app.UseDeveloperExceptionPage和app.UseExcep ...

  9. VMwarm下安装ubuntu的一些问题

    1.终端无法输入中文的原因(未实践)  原文地址 2.Windows10下VMwarm(V15.5)和ubuntu14.04实现复制文件(已经实践)  转载路径

  10. C#中如何禁止WindowsMediaPlayer双击全屏显示

    问题描述:在项目中使用WindowsMediaPlayer播放视频时,双击会出现视频全屏的效果,而且视频恢复后会暂停,除非再次双击返回后才能正常播放.那么如何禁止WindowsMediaPlayer的 ...