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. Workbench download Document

    1. package.xml <?xml version="1.0" encoding="UTF-8"?> <Package xmlns=&q ...

  2. 容器之 docker的监控平台(prometheus + Grafana)

    cAdvisor (Container Advisor) :用于收集正在运行的容器资源使用和性能信息.https://github.com/google/cadvisor Prometheus(普罗米 ...

  3. javase_note

    我上班摸鱼重新学习java基础做的笔记,从面向对象开始 面向对象基础 类与对象 人类.鸟类.鱼类...所谓类,就是对一类事物的描述 对象是某一类事物实际存在的每个个体,因此也称为实例 类是抽象概念,对 ...

  4. 苹果ios APP怎么打包?推荐这个网站

    众所周知,苹果的应用开发需要基于苹果电脑环境,而我们很多开发者并不具备这样的条件.如果你买一台贵的苹果电脑只是为了发布一个应用,成本太高了! 就算你有苹果电脑,你也可以自己开发一个基于web的IOS应 ...

  5. 数字图像处理 day1

    第一节 什么是图像 f(x y z λ t)z 立体  入 彩色 t 活动 f(x y) 静止的  单色 二值图像  黑白图像  灰度图像  彩色图像  点云图像 多光谱图像     我的理解是  建 ...

  6. 25 String 对象中的属性

    <!DOCTYPE html> <html lang="en">   <head>     <meta charset="UTF ...

  7. REST开发(1)

    REST风格 REST简介 Rest(Representational State Transfer),表现形式状态转换(访问网络资源的形式) 传统风格资源描述形式 http://localhost/ ...

  8. TS补充笔记

    TS掘金笔记:https://juejin.cn/post/6872111128135073806    *为疑惑点 类型总结: 2.6.1Enum类型数字枚举设置初始值: 2.6.1.1给第一个枚举 ...

  9. Python - Numpy 学习笔记

    #python - Numpy learning import numpy as np #---Numpy学习笔记---(第四章)--- #切片,浅拷贝 a = np.arange(10) print ...

  10. centos5.7 x64,安装java17,提示 glibc 版本低

    安装java17,网站下载tar版本. 解压后,配置/etc/profile 的java_home,和path, 运行java -version  和 javac -version  提升缺少GLIB ...