Codeforces Technocup 2017 - Elimination Round 2 E Subordinates(贪心)
题目链接 http://codeforces.com/contest/729/problem/E
题意:给你n个人,主管id为s,然后给你n个id,每个id上对应一个数字表示比这个人大的有几个。
最后问你有几个人搞错了。
一道简单的贪心题先将比自己大有i个人的存起来然后倒着贪心讲后面的补上前面不足的。当主管搞错时要特殊考虑一下
拿样例举例
(1)
3 2
2 0 2
(上司数) 0 1 (个数)
1 0
2 2
这样显然不符合因为上司为1个的没有而上司为2个的却有2个,所以一定要吧补上一个上司为1的所以有一个人犯错了。
5 3
1 0 0 4 1
(上司数) 0 2(个数)
1 2
2 0
3 0
4 1
显然这样也不符合不再解释,所以只要把上司为4的往上补就行了。还有要优先处理上司为0的犯错者因为主管只有一个那个人肯定犯错了
所以大致思路就是优先将上司为0的犯错者先往后补,再将后面往前补0最后要达成一串连续不为0的串即可。
#include <iostream>
#include <cstring>
using namespace std;
const int M = 2e5 + 10;
int a[M] , b[M];
int main()
{int n , m;cin >> n >> m;for(int i = 0 ; i < n ; i++) {cin >> a[i + 1];b[a[i + 1]]++;}if(a[m] != 0) {int count = 0;b[a[m]]--;b[0]++;count++;int temp = 0;int sum = 0;int gg = n - 1;if(b[0] > 1) {temp = b[0] - 1;count += temp;}for(int i = 0 ; i < n ; i++) {if(b[i] > 0) {sum += b[i];}else {while(b[gg] == 0) {gg--;}if(temp == 0) {b[gg]--;sum++;count++;}if(temp != 0) {temp--;}b[i]++;}if(sum == n) {break;}}cout << count << endl;return 0;}else {int count = 0;int temp = 0;int sum = 0;int gg = n - 1;if(b[0] > 1) {temp = b[0] - 1;count += temp;}for(int i = 0 ; i < n ; i++) {if(b[i] > 0) {sum += b[i];}else {while(b[gg] == 0) {gg--;}if(temp == 0) {b[gg]--;sum++;count++;}if(temp != 0) {temp--;}b[i]++;}if(sum == n) {break;}}cout << count << endl;}return 0;
}
转载于:https://www.cnblogs.com/TnT2333333/p/6083563.html
Codeforces Technocup 2017 - Elimination Round 2 E Subordinates(贪心)相关推荐
- Technocup 2020 - Elimination Round 2 E. Rock Is Push dp
传送门 文章目录 题意: 思路 题意: 给你一个n×mn×mn×m的方格,你初始在(1,1)(1,1)(1,1)点,有些位置有箱子,你可以走到某个位置向你的方向推动这个箱子,箱子不能出界,问你走到(n ...
- Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】...
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...
- szu cf套题训练Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3)A~D题解报告
A. Math Problem 题目大意:就是给你n个线段,你自己再添加一个线段d使得d和所有的线段都有交点,求d这个线段的最小长度是多少 解题思路: 1.首先看d线段的左端点,就是左端点选取的是所有 ...
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
一场挺简单的CF,但是我打炸了啊 A. Search for Pretty Integers time limit per test 1 second memory limit per test 25 ...
- Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4) 构造
传送门 文章目录 题意: 思路: 题意: 给nnn个数,让你构造一个尽可能大的矩阵,其中每个点所在的行和列都不含相等元素. 思路: 假设构造的答案矩阵大小为a×ba×ba×b且a<=ba< ...
- Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4) dfs + 思维
传送门 文章目录 题意: 思路: 题意: 给一张图,求必须经过aaa点和bbb点的路径条数. 思路: 通过观察我们发现,这个路径无非就是x−>a−>b−>yx->a->b ...
- Codeforces Round #759 (Div. 2, based on Technocup 2022 Elimination Round 3)
感觉E思路明确只用了stl+树状数组,F线段树复合修改,为什么都是2400. A. Life of a Flower B. Array Eversion C. Minimize Distance E. ...
- Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1)
A. Windblume Ode 题意是给你一个数组.然后要你求得一个子序列,这个子序列每个数的和是一个合数,并且是该数组能得到的最大的合数.输出这个子序列中每个元素的下标. 一开始看到这个题目的n的 ...
- E. New Game Plus!(Technocup 2021 - Elimination Round 2)
New Game Plus! https://codeforces.com/contest/1415/problem/E 感觉比D题要更简单 题面翻译 [题目大意] 你有 n n n 个数 c 1 ⋯ ...
最新文章
- Bag标签之中的一个行代码实行中文分词实例2
- mysql参数thread_cache和table_cache详解
- ads in shanghai
- Linux 整理笔记
- python版本及ML库
- VMware下Ubuntu无法全屏显示问题
- java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key c
- 导航第四版-分类专栏
- Django模型修改及数据迁移
- ubuntu终端安装python_Ubuntu linux下安装python3(手动安装)
- jQuery Mobile中图标icon样式大全ui-icon-*
- Linux下编译环境及Makefile的学习笔记
- 五个最佳编程文本编辑器
- 单片机 上传服务器协议,单片机数据上传到云服务器
- haneWIN Software NFS工具的使用
- 基于Python的Climate Indices库计算SPEI(标准化降水蒸散发指数)03—单站点不同时间尺度的SPEI计算
- 简单实现手机号验证码注册功能
- 【CF802O】April Fools‘ Problem (hard)(wqs二分,模拟费用流,老鼠进洞)
- 必应壁纸php,PHP版Bing壁纸下载源码
- vscode 插入多个光标,实现同时多行编辑的快捷键