题目链接 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. C语言编程学习打造——做题游戏

    C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现 ...

  2. k8s学习02-----kubeadm部署k8s

    机器规划 系统配置 三台机器都执行 1.关闭selinux及firewalld sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux ...

  3. oracle 断电启动失败:ORA-00600: internal error code, arguments

    转载地址: http://www.2cto.com/database/201312/261602.html 由于服务器断电,启动 oracle 时报 ORA-00600 错误 查看 oracle tr ...

  4. CentOS 7服务器安装brook和bbr加速

    一.安装Brook 执行一键部署脚本 $ wget -N --no-check-certificate wget -N --no-check-certificate https://raw.githu ...

  5. 基于tp3.2的腾讯云短信验证码的实现

    新手小白在公司要完成短信验证码注册功能,最初由于没有经验,网上的教程又不是很全,便参考着官方API文档,进行开发 直接进入正题:使用composer下载腾讯云短信接口(记得添加依赖).在项目目录下新建 ...

  6. WPF中TimeSpan的坑

    记一次在WPF中,在将格式为“DD.HH:mm:ss”字符串转换成TimeSpan时遇到的坑 如果字符串为:DD.HH:mm:ss,转换结果正确.例如: var currentValue = &quo ...

  7. eclipse项目导入idea jdk版本不一致😵

    在导入eclipse项目到idea过程中遇到 Imported project refers to unkonwn jdks JavaSE-1.8 解决方法: file --> Project ...

  8. canvas 鼠标位置缩放图形

    最近再做 webcad , 需要在 canvas  上对图形进行缩放,主要分为以下几个步骤: 1.找到当前光标所在位置,确定其在相对 canvas 坐标系的坐标 绑定鼠标滚轮事件,假定每次缩放比例 0 ...

  9. zuul集成Sentinel最新的网关流控组件

    一.说明 Sentinel 网关流控支持针对不同的路由和自定义的 API 分组进行流控,支持针对请求属性(如 URL 参数,Client IP,Header 等)进行流控.Sentinel 1.6.3 ...

  10. Go_笔试题记录-指针与值类型实现接口的区别

    1.如果Add函数的调用代码为: func main() { var a Integer = 1 var b Integer = 2 var i interface{} = &a sum := ...