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的更多相关文章

  1. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  2. 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 ...

  3. 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 ...

  4. cf380D Sereja and Cinema 组合数学

              time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  5. Cinema 4D R16安装教程

    CINEMA 4D_百度百科 http://baike.baidu.com/view/49453.htm?fr=aladdin 转自百度贴吧 [教程]Cinema 4D R16新功能介绍及安装教程_c ...

  6. ZOJ 3635 Cinema in Akiba(线段树)

    Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is ful ...

  7. ZOJ 3635 Cinema in Akiba[ 大规模阵列 ]

    门户:problemCode=3635">ZOJ 3635 Cinema in Akiba Time Limit: 3 Seconds      Memory Limit: 65536 ...

  8. Road to Cinema

    Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. Codeforces Round #350 (Div. 2) C. Cinema

    Moscow is hosting a major international conference, which is attended by n scientists from different ...

  10. 【3D动画建模设计工具】Maxon Cinema 4D Studio for Mac 20.0

    图标 Icon   软件介绍 Description Maxon Cinema 4D Studio R20 ,是由德国公司Maxon Computer一款适用于macOS系统的3D动画建模设计工具,是 ...

随机推荐

  1. JDK-11.0.17 + Neo4j-4.4.12

    JDK安装 下载地址:https://www.oracle.com/java/technologies/javase-downloads.html 注册Oracle账户,并下载,选择路径安装,将bin ...

  2. keil调试教程

    点击跳转 如果开启调试就提示弹框错误2k,说明你没有破解你的keil,网上自行下载注册机. 调试一定要对应自己板子的晶振,否则当你测试你的延时实际时间时,keil里的sec会不一样,甚至离谱.

  3. du命令_Linux du命令:查看文件夹和文件的磁盘占用情况

    du 命令,全称是 disk usage,用来展示磁盘使用量的统计信息. du 和 df 算是一对同门师兄弟,du 侧重在文件夹和文件的磁盘占用方面,而 df 则侧重在文件系统级别的磁盘占用方面.这两 ...

  4. 【实验】VUE依赖版本,遇到就看这里

    https://www.cnblogs.com/luomanman/p/15435422.html

  5. SQL 错误 [1105] [HY000]: errCode = 2, detailMessage = select list expression not produced by aggregation output (missing from GROUP BY clause?): ......

    SQL 错误 [1105] [HY000]: errCode = 2, detailMessage = select list expression not produced by aggregati ...

  6. Pytorch实战学习(四):加载数据集

    <PyTorch深度学习实践>完结合集_哔哩哔哩_bilibili Dataset & Dataloader 1.Dataset & Dataloader作用 ※Datas ...

  7. async/await和promise的执行顺序

    原题: async function async1() { console.log("async1 start"); await async2(); console.log(&qu ...

  8. GoLand 和 Pycharm的 快捷键设置与常用插件

    GoLand 插件 Gopher 美化进度条,让等待更优雅. CodeGlance pro 旁边浏览框. 快捷键设置 删除行: ctrl + L 重新格式化代码 ctrl + K 开始新行 ctrl ...

  9. 掌控安全学院SQL注入靶场延时注入

    第一关 第二关

  10. [转并修改]C#编程中跨线程访问控件

    C#编程中跨线程访问控件 一.简述 二.Winforms中跨线程访问控件 三.WPF中跨线程访问控件 参考文档 一.简述 C#中不允许跨线程直接访问界面控件,即一个线程中如主线程创建的控件不允许被其他 ...