Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心
1 second
256 megabytes
standard input
standard output
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
The first line contains two positive integers n and s (1 ≤ n ≤ 2·105, 1 ≤ s ≤ n) — the number of workers and the id of the chief.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Print the minimum number of workers that could make a mistake.
3 2
2 0 2
1
5 3
1 0 0 4 1
2
In the first example it is possible that only the first worker made a mistake. Then:
- the immediate superior of the first worker is the second worker,
- the immediate superior of the third worker is the first worker,
- the second worker is the chief.
题意:给你n个人,每个人只有一个大佬,大佬可能有大大佬,但是只有一个boss,boss没有大佬;
告诉你哪个是boss,和每个人大佬,大大佬,大大大佬。。。的个数,问最小几个人是错误的;
思路:如果当前深度为空,用最深的那个堵上,答案加一;
#include<bits/stdc++.h>
using namespace std;
const int N=,mod=1e9+,MOD=;
int a[N],flag[N];
int main()
{
int n,s;
scanf("%d%d",&n,&s);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
flag[a[i]]++;
}
int now=,ans=,z=n;
if(a[s]!=)
ans+=flag[]+,now=flag[],z-=flag[]+,flag[a[s]]--;
else
ans+=flag[]-,now=flag[]-,z-=flag[];
for(int i=;i<n;i++)
{
if(z<=)break;
if(!flag[i])
{
ans++;
if(now)
{
ans--;
now--;
}
else
{
z--;
} }
else
{
z-=flag[i];
}
}
printf("%d\n",ans);
return ;
}
Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心的更多相关文章
- 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 Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法
A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟
D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 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 ...
随机推荐
- java总结第四次//常用类
六.常用类 主要内容:Object类.String类.Date类.封装类 (一)Object类 1.Object类是所有Java类的根父类 2.如果在类的声明中未使用extends关键字指明其父类,则 ...
- 前端开发自动化工作流工具,JavaScript自动化构建工具grunt、gulp、webpack介绍
前端开发自动化工作流工具,JavaScript自动化构建工具grunt.gulp.webpack介绍 前端自动化,这样的一个名词听起来非常的有吸引力,向往力.当今时代,前端工程师需要维护的代码变得及为 ...
- settings.xml
<settings> <!--本地仓库.该值表示构建系统本地仓库的路径.其默认值为~/.m2/repository,windows:C:/Users/Administrator/.m ...
- 解决HP服务器安装Centos7 x64无法识别硬盘
公司有一台老旧的HP服务器——HP BL460c G7 SmartArray P410i.由于种种原因,需要重新安装操作系统Centos7.但是经过各种努力,Centos7的安装程序就是无法识别服务器 ...
- anroid 查看签名信息的方法
1.把app改成压缩文件 2.解压以后找到META-INF\CERT.RSA 3.在CMD命令行里面输入: keytool -printcert -file E:\META-INF\CERT.RS ...
- android TextView加载html内容并加载图片
package com.example.textviewfromhtml; import java.net.URL; import android.app.Activity; import andro ...
- java 基本类型之间的转换
基本数据类型从低级到高级是:byte short int long float double ,char 类型比int 类型之后的都要低 下面通过一个例子说明: import javax.swing ...
- MFCC常用类介绍
http://www.cnblogs.com/lzmfywz/archive/2012/04/22/2465069.html CStatic CObject └CCmdTarget └CWnd └CS ...
- HDU(4528),BFS,2013腾讯编程马拉松初赛第五场(3月25日)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4528 小明系列故事——捉迷藏 Time Limit: 500/200 MS (Java/O ...
- python两个dataframe的合并
见http://pandas.pydata.org/pandas-docs/stable/merging.html