Codeforces Round #558 B2. Cat Party (Hard Edition)
题面:
题目描述:
题目分析:
1.每个不同的数字只出现1次,例:1,2,3,4,52.只有一种数字,例:1,1,1,1,13.只有一种数字出现1次,其他数字出现的次数相同,例:1,1,1,2,2,2,34.有一种数字出现的次数比其他数字都多出1次,例:1,1,2,2,3,3,3
我们开一个叫same_cnt的数组,那么对于这组数据:1,1,2,2,3,3,4,4,4其中same_cnt[2] = 3(因为数字1,2,3的数量是2,共3个)same_cnt[3] = 1(因为数字4的数量是3,共1个)
1 #include <bits/stdc++.h>
2 using namespace std;
3 const int maxn = 1e5+5;
4 int u[maxn];
5 int cnt[maxn];
6 int same_cnt[maxn];
7
8 int main(){
9 int n;
10 scanf("%d", &n);
11 for(int i = 1; i <= n; i++){
12 scanf("%d", &u[i]);
13 }
14
15 int res = 0;
16 int mx = 0;
17 for(int i = 1; i <= n; i++){
18 cnt[u[i]]++;
19 same_cnt[cnt[u[i]]-1]--;
20 same_cnt[cnt[u[i]]]++;
21
22 mx = max(mx, cnt[u[i]]); //小技巧,自己领会一下
23 int ok = 0;
24
25 if(same_cnt[1] == i) ok = 1; //第一种情况:数量为1的有i个
26 else if(same_cnt[i] == 1) ok = 1; //第二种情况:数量为i的有1个
27 //第三种情况
28 else if(same_cnt[1] == 1 && same_cnt[mx]*mx == i-1) ok = 1;
29 //第四种情况
30 else if(same_cnt[mx] == 1 && same_cnt[mx-1]*(mx-1) == i-mx) ok = 1;
31
32 if(ok) res = i;
33 }
34
35 printf("%d\n", res);
36 return 0;
37 }
Codeforces Round #558 B2. Cat Party (Hard Edition)的更多相关文章
- Codeforces Round #558 (Div. 2)
目录 Codeforces Round #558 (Div. 2) 题解 A Eating Soup B Cat Party C Power Transmission D Mysterious Cod ...
- Codeforces Round #558 (Div. 2)-Cat Party (Hard Edition)-(前缀和 + 模拟)
http://codeforces.com/problemset/problem/1163/B2 题意:有n天,每天有一个颜色,截取前x天,随便抽掉一天,使剩下的各个颜色出现的次数相等. 解题,也可以 ...
- Codeforces Round 558(Div 2)题解
这场比赛没有打,后来和同学们一起开了场镜像打…… B是SB题结果WA了5发…… C是SB题结果差5min调出……虽然中间有个老师讲题吃掉了1h D是比较神仙的题(2200),但是做出来了?算是比较超常 ...
- 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)C(计算几何,排列组合,模拟)
#include<bits/stdc++.h>using namespace std;typedef struct{ double k,b;}node;node k[1000007];bo ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题
B. Problems for Round 题目连接: http://www.codeforces.com/contest/673/problem/B Description There are n ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B
B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题
连接在这里,->点击<- A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabyte ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
随机推荐
- 5分钟看懂Code128条形码
什么是Code128条形码? 相信大家看到这个都不陌生吧 1.前言 条形码种类很多,常见的大概有二十多种码制,其中包括:Code39码(标准39码).Codabar码(库德巴码).Code25码(标准 ...
- PAT L2-016. 愿天下有情人都是失散多年的兄妹 (BFS)
L2-016. 愿天下有情人都是失散多年的兄妹 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 呵呵.大家都知道五服以内不得通婚 ...
- Leetcode(17)-电话号码的字母组合
给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" 输出:[&quo ...
- 一个汉字在php中占几个字节?
问:一个汉字在php中占几个字节? 答: 对于中文字符,若使用 GBK.Big-5 版本,每个中文字符相当于 2 个字节: 若使用 UTF-8 版本,每个中文字符相当于 3 个字节.
- webpack remove console.log
webpack remove console.log https://stackoverflow.com/questions/41040266/remove-console-logs-with-web ...
- ASP.Net MVP Framework had been dead !
ASP.Net MVP Framework Project Description A project to get you started with creating and designing w ...
- Swift Playground All In One
Swift Playground All In One Swift 5.3 Playgrounds in Xcode Xcode 11.5 https://developer.apple.com/vi ...
- HTTP/2 & Push Cache
HTTP/2 & Push Cache HTTP/2 & 推送缓存 https://caniuse.com/#search=http2 https://jakearchibald.co ...
- project config generator
project config generator React, Vue, https://createapp.dev/ parcel https://parceljs.org/ https://git ...
- “Fatal error: Unable to find local grunt.” when running “grunt” command
下载到本地 >npm install grunt >grunt 命令行运行:grunt,出现以下问题: 这些是Gruntfile.js中引用的,依次安装: npm install grun ...