题目大意:

一共有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. springboot项目自定义注解实现的多数据源切换

    一.主要依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spri ...

  2. Spring Maven工程引入css,js

    1.CSS <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet" type="t ...

  3. ASP.NET MVC4中的异步控制器

    在抛弃了对.NET 3的支持之后, ASP.NET MVC 4 彻底拥抱了Task类库, 你不需要再蛋疼的给每个Action写两个方法, 也无需傻傻的手动对异步Action计数器增减了(AsyncMa ...

  4. [转载]Oracle创建表空间、创建用户以及授权

    Oracle安装完后,其中有一个缺省的数据库,除了这个缺省的数据库外,我们还可以创建自己的数据库. 为了避免麻烦,可以用’Database Configuration Assistant’向导来创建数 ...

  5. 2个CDH的hive数据同步

    算法和数仓共用一套hive数据: CM: 真实数据: 都存在共享存储: oss, s3,ufile上. CDH配置能访问的权限(key)

  6. PS错误1

    PS错误1 提示要卸载.不用卸载直接安装即可.还保留了之前的设置. 在安装目录下看看有没有安装PS的exe程序.可能有.

  7. 用css美化select框

    先上代码: .selectData{ height: 0.42rem; position: absolute; right:.28rem; top:.30rem; //去边框 border: none ...

  8. 脉脉的一道网红Java面试题

    题目如下: public class Test { public static void main(String[] args) { int a = 10; int b = 10; // 需要在met ...

  9. 向前引用 ? float VS long ? 这些知识你懂吗?

    thinking in java 读书笔记(感悟): 作者:淮左白衣 : 写于 2018年4月2日18:14:15 目录 基本数据类型 float 和 long 谁更大 System.out.prin ...

  10. 公式编辑器之 AxMath(18)

    1. 使用教程 视频教程,一共有18集,每集都比较短. >> 视频教程链接:B站,速度快,清晰 2. 破解软件下载链接 >> 下载链接:复制链接到迅雷或IDM下载很快 3. M ...