题目大意:

一共有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. talking data 集成

    talking data 集成需要手动添加libz.td

  2. 汉化Git Gui

    先来一个图: 其实使用自带的图形化操作git还是很方便的,但是英文界面还是让相当一部分小伙伴不太舒服,比如我哈. 汉化包地址:链接: https://pan.baidu.com/s/1qQtBUsf1 ...

  3. 中检测到有潜在危险的 Request.Form 值

    经常会出现从客户端(xxx)中检测到有潜在危险的 Request.Form 值. 这个问题我们只用在web.config中添加一句代码即可 <system.web> <pages v ...

  4. mysql 查询某一天数据

    某个场景下需要查询某一天的数据,例如2017/9/27这一天所有的数据量,有以下几个方法. SELECT * FROM cms_book_statistics WHERE substring(Conv ...

  5. JavaScript form提交汉字乱码

    <script type="text/javascript"> var test1="http://www.w3school.com.cn/My first/ ...

  6. The Select mechanism in linux for block mechanism

    Today, some one mention theknowledge of Select Mechanism. It's better to konw something about it ! O ...

  7. 【51nod】1407 与与与与

    [51nod]1407 与与与与 设\(f(x)\) 为\(A_{i} \& x == x\)的\(A_{i}\)的个数 设\(g(x)\)为\(x\)里1的个数 \(\sum_{i = 0} ...

  8. (二)javaweb开发的常见概念总结(来自那些年的笔记)

    目录 WEB开发相关知识 WEB服务器 Tomcat服务器 WEB应用程序 配置WEB应用 配置缺省的WEB应用 Web设置首页 web.xml文件 配置虚拟主机 配置https连接器 为我们的网站, ...

  9. C/C++内存知识(一)

    一.C/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)- 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.其操作方式类似于数据结构中的栈. 2.堆区(heap)- 由程序 ...

  10. PAT(B) 1014 福尔摩斯的约会(Java)

    题目链接:1014 福尔摩斯的约会 注意 三个字眼:"第1对","第2对","第1对",因此如果你用了循环,别忘了break,因为后面也可能 ...