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(油箱容量). 车子有两种前进方式 ...
随机推荐
- codeforces 327 B. Hungry Sequence
题目链接 题目就是让你输出n个数的序列,要保证该序列是递增的,并且第i个数的前面不能保护它的约数,我直接先对前100000的素数打表,然后输出前n个,so easy. //cf 191 B #incl ...
- 【Laravel】 安装及常用的artisan命令
composer Laravel 安装 cmd composer create-project laravel/laravel Laravel5 之后自动创建 常用的artisan命令 全局篇 查看a ...
- Wpf窗口设置屏幕居中最前显示
public Window() { InitializeComponent(); WindowStartupLocation = Win ...
- JVM和GC的工作原理
转载于https://uestc-dpz.github.io JVM Java 虚拟机 Java 虚拟机(Java virtual machine,JVM)是运行 Java 程序必不可少的机制.JVM ...
- java基本数据类型和包装类之间的区别
1.声明方式不同,基本类型不适用new关键字,而包装类型需要使用new关键字来在堆中分配存储空间: 2.存储方式及位置不同,基本类型是直接将变量值存储在堆栈中,而包装类型是将对象放在堆中,然后通过引用 ...
- IBM实习工作(二)
2019年秋招前夕再次到ibm项目组参加实习两周,这次主要负责的需求是建立牛奶数据池,在二级菜单建立对账单数据池,数据由Excel导入生成. 分析整个需求,主要分为以下几块: 1.牛奶数据池前台页面, ...
- SpringBoot操作ES进行各种高级查询
SpringBoot整合ES 创建SpringBoot项目,导入 ES 6.2.1 的 RestClient 依赖和 ES 依赖.在项目中直接引用 es-starter 的话会报容器初始化异常错误,导 ...
- 暂停研发surging,是否继续维护!
前言 surging从2017 年开始,2 年来利用业余时间为 surging语言添砖加瓦. 这种活雷锋行为并没有得到开发者们的理解,很多人甚至用命令的口吻,灵魂拷问方式要求活雷锋们再苦再累也得免费为 ...
- 网页如何设置favicon.ico
1.首先制作ico图,并命名favicon.ico 2.将文件放在项目的根目录下
- Go最火的Gin框架简单入门
Gin 介绍 Gin 是一个 Golang 写的 web 框架,具有高性能的优点,,基于 httprouter,它提供了类似martini但更好性能(路由性能约快40倍)的API服务.官方地址:htt ...