Subordinates(贪心)
题目大意:
一共有N个员工,其中最高领导人是编号s的人,每个人都只有一个直接领导,每个人都说出了自己领导的个数,问最少有几个人撒谎了。
思路: 合理的贪心是该把排最后的数变成缺少的数字,然后继续判断。 (不一定非要01234 可以011223)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define se second
#define fi first
const int INF= 0x3f3f3f3f;
const int N=2e5+; int a[N]; int main()
{
int n,s,cnt=;
cin>>n>>s;
for(int i=;i<n;i++){
cin>>a[i];
if(i!=s- && a[i]== ) a[i]=INF;
}
if(a[s-]) cnt++,a[s-]=;
sort(a,a+n);
int j=,i=;
while(i<=n-) //从i=1开始
{
if(a[i]==j)
{
while(a[i]==j)
i++;
}
else
cnt++,n--;
j++;
}
cout<<cnt<<endl;
}
或者
int main(){
scanf("%d%d", &n, &s);
int cnt = ;
for(int i=; i<=n; i++){
scanf("%d", &a[i]);
if(i==s&&a[i]!=){
cnt++;
a[i] = ;
}
else if(i!=s&&a[i]==){
a[i] = n;
}
num[a[i]]++;
}
sort(a+,a++n);
int t = ;
for(int i=; i<n; i++){
if(num[i]==){
cnt++;
num[i]++;
}
t+=num[i];
if(t>=n)break;
}
printf("%d\n",cnt);
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 Round #380 (Div. 2)/729E Subordinates 贪心
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a ...
- Codeforces #380 Subordinates(贪心 构造)
从前往后扫,找到一出现次数为0的数,从后面找一个出现不为0的数转化而来.设置两指针l, r来处理. #include<cstdio> #include<iostream> #i ...
- Codeforces Technocup 2017 - Elimination Round 2 E Subordinates(贪心)
题目链接 http://codeforces.com/contest/729/problem/E 题意:给你n个人,主管id为s,然后给你n个id,每个id上对应一个数字表示比这个人大的有几个. 最后 ...
- Codeforces 729E Subordinates
题目链接:http://codeforces.com/problemset/problem/729/E 既然每一个人都有一个顶头上司,考虑一个问题: 如果这些人中具有上司数目最多的人有$x$个上司,那 ...
- sgu 195 New Year Bonus Grant【简单贪心】
链接: http://acm.sgu.ru/problem.php?contest=0&problem=195 http://acm.hust.edu.cn/vjudge/contest/vi ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- 解决maven打包时,会编译特定文件导致文件不可用
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resou ...
- Python中最常见的10个问题(列表)
列表是Python中使用最多的一种数据结果,如何高效操作列表是提高代码运行效率的关键,这篇文章列出了10个常用的列表操作,希望对你有帮助. 1.迭代列表时如何访问列表下标索引 普通版: items = ...
- 乐字节Java反射之一:反射概念与获取反射源头class
一.Java反射机制概念 “程序运行时,允许改变程序结构或变量类型,这种语言称为动态语言”,如Python, Ruby是动态语言:显然C++,Java,C#不是动态语言,但是JAVA有着一个非常突出 ...
- Snapshot Array
Implement a SnapshotArray that supports the following interface: SnapshotArray(int length) initializ ...
- pgsql常用操作
pgsql备份: --进入pgsql容器docker exec -it 容器ID bash --备份pgsql /opt/rh/rh-postgresql95/root/usr/bin/pg_dump ...
- [转帖]AIDA64 6.10版发布:全面支持中国兆芯、海光x86 CPU
AIDA64 6.10版发布:全面支持中国兆芯.海光x86 CPU https://www.cnbeta.com/articles/soft/892877.htm 支持国产x86了 作为硬件识别工具领 ...
- mysql中information_schema.tables字段说明
1. 获取所有表结构(TABLES) SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA='数据库名'; TABLES表: ...
- 【转】spring基础:@ResponseBody,PrintWriter用法
理解:很多情况我们需要在controller接收请求然后返回一些message. 1.在springmvc中当返回值是String时,如果不加@ResponseBody的话,返回的字符串就会找这个St ...
- Vue解决项目白屏
第一步: vue-cli项目根目录下面新建Vue.config.js文件 proxy反向代理 module.exports = { devServer: { proxy: { ...
- (转) 从0移植uboot(五) _实现串口输出
ref : https://www.cnblogs.com/xiaojiang1025/p/6500520.html 串口作为一种非常简单的通信方式,才是嵌入式系统调试的王道,通过设置串口输出,我们可 ...