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;
}
Codeforces Technocup 2017 - Elimination Round 2 E Subordinates(贪心)的更多相关文章
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心
E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Technocup 2017 - Elimination Round 2 D. Sea Battle(贪心)
题目链接 http://codeforces.com/contest/729/problem/D 题意:给你一个1*n的区域有a艘船,每艘船宽b,已经开了k枪都没打到,问你最少再开几枪至少能打到一艘船 ...
- Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)
http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C
Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B
Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A
Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法
A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...
随机推荐
- 线上调试bug
在以往的工作中,线上一有bug,就需要把文件弄到本地来改,但经常会碰见本地环境又和线上不一样,导致调试困难,闭着眼睛改好之后传到线上去看对不对,不对的话又要改,循环往复,要多麻烦就有多麻烦啊. 今天给 ...
- ASP.NET Core - 实现自定义WebApi模型验证
Framework时代 在Framework时代,我们一般进行参数验证的时候,以下代码是非常常见的 [HttpPost] public async Task<JsonResult> Sav ...
- 派胜OA二次开发笔记(1)重写主界面
最近从派胜OA 2018 升级到 2019,为了二次开发方便,索性花了两天,反向分析 PaiOA 2019 主界面程序,重写大部分代码,方便对菜单权限进行控制. 主界面/core/index.aspx ...
- 优雅的对象转换解决方案-MapStruct使用进阶(二)
在前面, 介绍了 MapStruct 及其入门. 本文则是进一步的进阶. 在 MapStruct 生成对应的实现类的时候, 有如下的几个情景. 1 属性名称相同,则进行转化 在实现类的时候, 如果属性 ...
- redhat linux 5.3安装activeMQ
安装环境:linux redhat enterprise 5.3 activemq版本:5.9.01.从http://activemq.apache.org/download.html地址下载apac ...
- nginx在线与离线安装
1.场景描述 项目要部署到新的服务器上,需要安装nginx,刚好安全部门通知了nginx存在安全漏洞(Nginx整数溢出漏洞,nginx1.13.2之后的版本无问题),就下载最新的nginx进行了安装 ...
- Java连载16-++传参&关系运算符
一.++再举例 int a = 10; System.out.print(a++);//这里会打印出10,因为他们内部这个print函数有参数相当于参数x=a++ System.out.println ...
- 管理Windows Server 2008本地用户和组
下面介绍Windows Server 2008本地用户和组的管理包括创建用户.删除用户.重设密码.将用户添加到组.普通用户跟管理员的区别 .用户配置文件包括桌面上文件,桌面背景,桌面上图标,IE设置, ...
- JS之null与undefined的区别
null表示尚未存在的对象 js 代码: alert(null == document.getElementById('notExistElement')); //output "true ...
- java120经典面试题
经典面试题 -----version 1.0 题注:以下答案仅限本人个人见解,若有错误和建议请多多指教.QQ:1807812486 题目来源 1.什么是Java虚拟机?为什么Java被称作是" ...