题目大意:

一共有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(贪心)的更多相关文章

  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 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 ...

  3. Codeforces #380 Subordinates(贪心 构造)

    从前往后扫,找到一出现次数为0的数,从后面找一个出现不为0的数转化而来.设置两指针l, r来处理. #include<cstdio> #include<iostream> #i ...

  4. Codeforces Technocup 2017 - Elimination Round 2 E Subordinates(贪心)

    题目链接 http://codeforces.com/contest/729/problem/E 题意:给你n个人,主管id为s,然后给你n个id,每个id上对应一个数字表示比这个人大的有几个. 最后 ...

  5. Codeforces 729E Subordinates

    题目链接:http://codeforces.com/problemset/problem/729/E 既然每一个人都有一个顶头上司,考虑一个问题: 如果这些人中具有上司数目最多的人有$x$个上司,那 ...

  6. sgu 195 New Year Bonus Grant【简单贪心】

    链接: http://acm.sgu.ru/problem.php?contest=0&problem=195 http://acm.hust.edu.cn/vjudge/contest/vi ...

  7. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  8. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  9. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. 用户登录时,禁止chrome提示用户保存密码

    将input的type=“password”改为type=“text” 在获得焦点后,将type改为password <input class="iptpsw form-control ...

  2. springboot和solr结合测试使用

    首先新建springboot项目 新建webapp目录 springboot没有webapp目录——手动添加 web.xml <?xml version="1.0" enco ...

  3. JVM -- 对象的概述和引用

    一.概述 说起垃圾收集(Garbage Collection,GC),大部分人都把这项技术当做java语言的伴生产物,然后GC出现历史比java久远. GC需要完成的3件事情: 1.哪些内存需要回收 ...

  4. Python之正则表达式笔记

    概述 概念 Regular Expression 一种文本模式,描述在搜索文本时要匹配的一个或多个字符串 典型场景 数据验证.文本扫描.文本提取.文本替换.文本分割 语法 字面值 普通字符 需转义:\ ...

  5. 编码方式之ASCII、ANSI、Unicode概述

    1.ASCII ASCII全称(American Standard Code for Information Interchange)美国信息交换标准代码,在计算机内部中8位二进制位组成1个字节(8( ...

  6. 『Python基础练习题』day02

    1.判断下列逻辑语句的True, False 1) 1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 2) ...

  7. js中 this 的指向

    js中 this的指向一共存在3种地方: 1.全局的this; 2.构造函数的this; 3.call/apply; 一.全局的this: function test(){ this.d = 3;// ...

  8. CSS一些常用样式

    限制行数溢出省略号 display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: ; overflow: hidden ...

  9. 配置vue 多页面

    安装vue 1. 全局安装 vue-cli环境 npm install --global vue-cli 2. 创建一个基于webpack模板的新项目 vue init webpack my-proj ...

  10. 用jq动态给导航菜单添加active

    点击后页面跳转到了新的链接,找到所有的li下的a标签,对其链接地址进行判断,如果和当前浏览器的地址一致,就认为是当前应该激活的菜单,添加active类,否则就取消. <ul class=&quo ...