题目链接 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(贪心)的更多相关文章

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

  2. Codeforces Technocup 2017 - Elimination Round 2 D. Sea Battle(贪心)

    题目链接 http://codeforces.com/contest/729/problem/D 题意:给你一个1*n的区域有a艘船,每艘船宽b,已经开了k枪都没打到,问你最少再开几枪至少能打到一艘船 ...

  3. 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,到每 ...

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

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

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

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

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

  9. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

随机推荐

  1. SQL注入详解及技巧

    Tip小技巧 :在白盒测试的过程中,在sql语句的下一句加上 echo $sql. '<br>'; 可以在页面中输出完整的sql语句 效果图 :

  2. js 实现 联动

    使用jQuery实现联动效果 应用场景:收货地址 1.准备三个下拉框 <select class="changeArea" id='province'> <opt ...

  3. java8中使用函数式接口

    使用函数式接口 Predicate @FunctionalInterface interface Predicate<T>{ boolean test(T t); } public sta ...

  4. 第四章 文件的基本管理和XFS文件系统备份恢复 随堂笔记

    第四章 文件的基本管理和XFS文件系统备份恢复 本节所讲内容: 4.1 Linux系统目录结构和相对/绝对路径. 4.2 创建/复制/删除文件,rm -rf / 意外事故 4.3 查看文件内容的命令 ...

  5. hadoop学习(三)----hadoop2.x完全分布式环境搭建

    今天我们来完成hadoop2.x的完全分布式环境搭建,话说学习本来是一件很快乐的事情,可是一到了搭环境就怎么都让人快乐不起来啊,搭环境的时间比学习的时间还多.都是泪.话不多说,走起. 1 准备工作 开 ...

  6. 以kaldi中的yesno为例谈谈transition

    在基于GMM-HMM的传统语音识别里,比音素(phone)更小的单位是状态(state).一般每个音素由三个状态组成,特殊的是静音(SIL)由五个状态组成.这里所说的状态就是指HMM里的隐藏的状态,而 ...

  7. 防止sql注入:替换危险字符

    在用户名或者密码框中输入“11‘ or ’1‘ = '1”时,生成的sql语句将为“selec * from userInfo where name = '11' or '1' = '1' and p ...

  8. SpringBoot操作ES进行各种高级查询

    SpringBoot整合ES 创建SpringBoot项目,导入 ES 6.2.1 的 RestClient 依赖和 ES 依赖.在项目中直接引用 es-starter 的话会报容器初始化异常错误,导 ...

  9. Spring Boot 中的同一个 Bug,竟然把我坑了两次!

    真是郁闷,不过这事又一次提醒我解决问题还是要根治,不能囫囵吞枣,否则相同的问题可能会以不同的形式出现,每次都得花时间去搞.刨根问底,一步到位,再遇到类似问题就可以分分钟解决了. 如果大家没看过松哥之前 ...

  10. 从Dictionary源码看哈希表

    一.基本概念 哈希:哈希是一种查找算法,在关键字和元素的存储地址之间建立一个确定的对应关系,每个关键字对应唯一的存储地址,这些存储地址构成了有限.连续的存储地址. 哈希函数:在关键字和元素的存储地址之 ...