Codeforces 729E Subordinates
题目链接:http://codeforces.com/problemset/problem/729/E
既然每一个人都有一个顶头上司,考虑一个问题:
如果这些人中具有上司数目最多的人有$x$个上司,那么一定存在一些人,他们分别有$x-1,x-2...1$个上司。
首先如果$s$位置上的上司数目不为$0$,非$s$位置上的上司数目为$0$它们就是一定说错了话的。
问题转化为了:将合法的上司数目从小到大小排序,我们现在要这个序列的数字连续单调不降,并且相差不能为大于$1$。
有一人些已经说错了话,考虑用他们补足中间的差值的空隙,如果补不足再贪心的把最大的减小往前补。
注意如果最后一个人和前一个人差值有间隙,直接把它他减小即可。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 1001000
#define llg int
#define inf 0x7fffffff
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,la,a[maxn],ans,s;
bool bj[maxn];
int main()
{
yyj("Subordinates");
cin>>n>>s;
for (llg i=;i<=n;i++)
{
scanf("%d",&a[i]);
if (i==s)
{
if (a[i]!=) ans++;
a[i]=;
}
if (a[i]== && i!=s) a[i]=inf,ans++;
}
sort(a+,a+n+);
bj[]=; la=;
for (llg i=;i<=n;i++)
{
if (a[i]== || a[i]==inf) continue;
if (!bj[a[i]-])
{
if (a[n]!=inf) ans++;
bj[la]=; la=la+;
if (n!=i) i--;
n--;
continue;
}
bj[a[i]]=; la=a[i]+;
}
cout<<ans;
return ;
}
Codeforces 729E Subordinates的更多相关文章
- Codeforces #380 div2 E(729E) 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 738E Subordinates
排序,构造. 相当于告诉我们一棵树$n$个节点,每个节点在哪一层,至少需要移动多少个节点,才能让这些节点变成一棵树. 按照层次排个序移动一下就可以了,优先选择那些不是$s$但是层次是$0$的节点,如果 ...
- 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 738E】Subordinates
[题目链接]:http://codeforces.com/problemset/problem/738/E [题意] 给你一个类似树形的关系; 然后告诉你某个人头顶上有多少个上司numi; 只有fat ...
- Codeforces Technocup 2017 - Elimination Round 2 E Subordinates(贪心)
题目链接 http://codeforces.com/contest/729/problem/E 题意:给你n个人,主管id为s,然后给你n个id,每个id上对应一个数字表示比这个人大的有几个. 最后 ...
- Subordinates CodeForces - 737C (树,构造)
大意: 求构造一棵树, 每个节点回答它的祖先个数, 求最少打错次数. 挺简单的一个构造, 祖先个数等价于节点深度, 所以只需要确定一个最大深度然后贪心即可. 需要特判一下根的深度, 再特判一下只有一个 ...
- Codeforces Beta Round #6 (Div. 2 Only) B. President's Office 水题
B. President's Office 题目连接: http://codeforces.com/contest/6/problem/B Description President of Berla ...
随机推荐
- 自写Jquery插件 Datagrid
原创文章,转载请注明出处,谢谢!https://www.cnblogs.com/GaoAnLee/p/9086582.html 废话不多说,先上个整体效果: html <div id='data ...
- 怎样从外网访问内网Jupyter Notebook?
本地安装了一个Jupyter Notebook,只能在局域网内访问,怎样从外网也能访问到本地的Jupyter Notebook呢?本文将介绍具体的实现步骤. 准备工作 安装并启动Jupyter Not ...
- 离开(切换)当前页面时改变页面title
document.addEventListener('visibilitychange', function () { if (document.visibilityState == 'hidden' ...
- Prometheus监控学习笔记之prometheus的远端存储
0x00 概述 prometheus在容器云的领域实力毋庸置疑,越来越多的云原生组件直接提供prometheus的metrics接口,无需额外的exporter.所以采用prometheus作为整个集 ...
- Linux三剑客grep、sed、awk
grep grep file grep -i file grep -v file
- centos6二进制安装mysql5.5
centos 6.5,安装mysql 5.5.60 所需安装包mysql-5.5.60-linux-glibc2.12-x86_64.tar.gz.ncurses-devel-5.7-4.200902 ...
- diff 命令实用
1.概述 本文将要讨论的是diff命令,diff用来比较两个文件.当然文件比较的工具很多,windows系统下面就有不错的工具可以使用,例如常用的Beyond Compare,WinMerge都是图形 ...
- Codeforces 798D Mike and distribution - 贪心
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...
- bzoj 2527 Meteors - 整体二分 - 树状数组
Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby gala ...
- shell 调试脚本设置
set -x 脚本部分内容 set +x