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 ...
随机推荐
- scala多个构造函数的定义方法
直接上代码: package com.test.scalaw.test.demo /** * scala定义多个构造函数, * 另外,Scala中有只有一个主要构造函数,其他都是辅助构造函数.而且需要 ...
- Linux系统的中断、系统调用和调度概述【转】
转自:http://blog.csdn.net/yanlinwang/article/details/8169725 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近学习Linux操作系统, ...
- mmap直接控制底层【转】
转自:http://blog.csdn.net/xyyangkun/article/details/7830149 版权声明:本文为博主原创文章,未经博主允许不得转载. 这是在mini6410上测试成 ...
- android:layout_gravity和android:gravity属性的区别
一.介绍: gravity的中文意思就是”重心“,就是表示view横向和纵向的停靠位置 (1).android:gravity:是对view控件本身来说的,是用来设置view本身的内容应该显示在vie ...
- MyBatis的Dao层注入SqlSession
有点坑爹,以前没用过Mybatis,最近才用,而且一直用Mybatis推荐的接口映射的方式,但是今天有人告诉我接口方式用得少,大多还是采用从配置文件里面读sql的方式,当然接口也是类似的,都是利用ma ...
- 打开开源项目总得.md文件
google了一些: 78 Tools for Writing and Previewing Markdown http://mashable.com/2013/06/24/markdown-too ...
- phpize的深入理解
安装(fastcgi模式)的时候,常常有这样一句命令:/usr/local/webserver/php/bin/phpize一.phpize是干嘛的?phpize是什么东西呢?php官方的说明:htt ...
- fragment相关
1.鸿洋大神前两年写的,从最基础的开始详解.对常用的方法都做了精炼的总结,分上下两篇 http://blog.csdn.net/lmj623565791/article/details/3797096 ...
- 在lua的string库和正则表达式
一.前提要了解一下lua 的string几个方法 1. string库中所有的字符索引从前往后是1,2,...;从后往前是-1,-2,... 2. string库中所有的function都不会直接操作 ...
- [团队项目]----Math Calculator
团队项目 ----Math Calculator 任务: 1.每个团队从Github上fork这个项目的源代码 https://github.com/RABITBABY/We-have-bing 2. ...