B. Going to the Cinema
https://codeforces.com/contest/1782/problem/B
题目大意就是给定n个人,每个人有一个除自己之外的最少陪同人数,选一部分人去电影院,要求去的人人数大于等于去的每个人要陪同的人数,不去的人要求陪同的人数要大于要求去的人数
废话不多说上代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=2e5+10;
int a[N],p[N];
int t;
int main(){
cin>>t;
while(t--){
int n;
cin>>n;
int m=0;
memset(p,0,sizeof p);
for(int i=1;i<=n;i++){
int x;
cin>>x;
if(p[x]==0) a[++m]=x;//记录每种陪同人数
p[x]++;//记录每种陪同人数的个数
}
sort(a+1,a+1+m);
//我们这里先排序,当序列由小到大时,我们发现如果后面的能去的话,前面的必须得去
int res=0,num=0;
//注意人数减一是因为不包含自己
for(int i=1;i<=m;i++){
if(num<a[i]&&max(num-1,0)>=a[i-1]) res++;//对于方案来说,如果该人不去是合法的则方案数加一
num+=p[a[i]];
}
if(num-1>=a[m]) res++;//最后判断一下是否所有人去都合法
cout<<res<<endl;
}
}
B. Going to the Cinema的更多相关文章
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- Codeforces #380 div2 C(729C) Road to Cinema
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- cf380D Sereja and Cinema 组合数学
time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- Cinema 4D R16安装教程
CINEMA 4D_百度百科 http://baike.baidu.com/view/49453.htm?fr=aladdin 转自百度贴吧 [教程]Cinema 4D R16新功能介绍及安装教程_c ...
- ZOJ 3635 Cinema in Akiba(线段树)
Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is ful ...
- ZOJ 3635 Cinema in Akiba[ 大规模阵列 ]
门户:problemCode=3635">ZOJ 3635 Cinema in Akiba Time Limit: 3 Seconds Memory Limit: 65536 ...
- Road to Cinema
Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #350 (Div. 2) C. Cinema
Moscow is hosting a major international conference, which is attended by n scientists from different ...
- 【3D动画建模设计工具】Maxon Cinema 4D Studio for Mac 20.0
图标 Icon 软件介绍 Description Maxon Cinema 4D Studio R20 ,是由德国公司Maxon Computer一款适用于macOS系统的3D动画建模设计工具,是 ...
随机推荐
- redis cluster 部署
redis cluster 部署 服务器说明 192.168.2.200:7000 ... 192.168.2.200:7005 创建集群目录 mkdir cluster-test cd cluste ...
- c# 调用User32.dll
获取当前窗口句柄:GetForegroundWindow()[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelli ...
- 生产中遇到的spark任务问题
spark版本 2.2.0 日志里面的信息: WARN RowBasedKeyValueBatch: Calling spill() on RowBasedKeyValueBatch. Will no ...
- Visual Studio 2013图标变白
今天一打开电脑,就发现我的Visual Studio 2013的图标变成白色的了,我点开程序发现程序照常可以运行. 于是我就百度,有的说看注册表,发现缺少文件,结果我也没缺,还有什么更换主题的,都不管 ...
- js获取各种高度的方法
js获取各种高度的方法 源文章:https://www.cnblogs.com/MrzhangRecord/p/9185868.html 目录 js获取各种高度的方法 1.获取元素的高度 模板:htm ...
- windows下搭建stm8s开发环境
拓扑:windows -> st_link_v2 ->目标板,目标板不由st_link_v2供电 接线: st_link_v2: NRST GND SWIM 3V3 ↓ ↓ ↓ ↓ 目标板 ...
- bootstrap table表格按钮
1 <body> 2 3 <form action="" method="POST" class="form-horizontal& ...
- React使用高阶组件与Hooks实现权限拦截教程
导读 高阶组件就是接受一个组件作为参数并返回一个新组件(功能增强的组件)的函数.这里需要注意高阶组件是一个函数,并不是组件,这一点一定要注意,本文给大家分享React高阶组件使用小结,一起看看吧 高阶 ...
- andriod app更新
对于安卓用户来说,手机应用市场说满天飞可是一点都不夸张,比如小米,魅族,百度,360,机锋,应用宝等等,当我们想上线一款新版本APP时,先不说渠道打包的麻烦,单纯指上传APP到各大应用市场的工作量就已 ...
- GIS空间分析和建模复习重点1
1.对空间分析的理解(对概念的理解) 空间分析是为了解答地理空间问题而进行的数据分析与挖掘,是GIS的核心.研究对象为空间目标(具有空间特性(位置,分布,形态,空间关系(距离,方位,拓扑)),属性特性 ...