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) ...
随机推荐
- js中遍历对象(5种)和遍历数组(6种)的方法总结(转载)
一.遍历对象方法 1.for...in遍历输出的是对象自身的属性以及原型链上可枚举的属性(不含Symbol属性),原型链上的属性最后输出说明先遍历的是自身的可枚举属性,后遍历原型链上的 eg: var ...
- react做的简单的选项卡
### 首先安装react的脚手架 cnpm install create-react-app -g 只需要在电脑下载安装一次即可 ###创建项目 create-react-ap ...
- Python(1)自动发送邮件
python发邮件需要掌握两个模块的用法,smtplib和email,这俩模块是python自带的,只需import即可使用.smtplib模块主要负责发送邮件,email模块主要负责构造邮件. sm ...
- 《Hadoop大数据技术开发实战》学习笔记(一)
基于CentOS7系统 新建用户 1.使用"su-"命令切换到root用户,然后执行命令: adduser zonkidd 2.执行以下命令,设置用户zonkidd的密码: pas ...
- Dapper存储过程以及多次查询和批量写入操作
一.存储过程操作 1. 准备存储过程 newsreturnvalue(该存储过程计算2个参数的和并返回) USE [ZPC.Contact] GO SET ANSI_NULLS ON GO SET Q ...
- JS获取URL参数中文乱码解决
var param = window.location.search; var paramArray = parseParams(param); var selectV = decodeURI(par ...
- selenium + python 环境配置 (二)之启动IE
安装好python.selenium工具后,下一步就是启动浏览器 1.启动IE浏览器 即Selenium 调用IEDriverServer打开IE浏览器 ,因此需下载对应的IEDriverServer ...
- 重新渲染layui的radio
修改后添加这一段 layui.use('form', function() { var form = layui.form; form.render(); }); 也可以用官方的方法:https:// ...
- [转载]Oracle中动态SQL详解
1.静态SQLSQL与动态SQL Oracle编译PL/SQL程序块分为两个种:其一为前期联编(early binding),即SQL语句在程序编译期间就已经确定,大多数的编译情况属于这种类型:另外一 ...
- 基于tesseract-OCR进行中文识别
1. 环境准备 1.1 下载 下载Tesseract-OCR安装包,地址为: https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w32- ...