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. PageHelper大致逻辑

    简单涉及以下几个类: PageHelper   PageMethod  PageParam PageInterceptor  implement Interceptor PageHelperAutoC ...

  2. kubernetes构架及组件介绍

    传统部署时代 早期在物理机上直接运行应用程序,无法对其定义资源边界,导致资源不分配,其他的程序性能下降 虚拟化部署时代 虚拟化允许应用程序在VM之间隔离,并提供安全界别,但是不能自由访问应用程序 因为 ...

  3. 解决在宝塔面板IIS服务器上部署svg/woff/woff2字体的问题

    部署网站的字体和服务器IIS有什么关系?如果你的职责只限于一名前端开发,那么你可能很"幸福"地与这些问题擦肩而过,浑然不觉.可是本人一直都是孤军奋战,连开发环境都要自己搭建,这次又 ...

  4. Mysql 索引心得

    1. 频繁查询的字段,应该创建索引. 2.更新非常频繁的字段,不应该创建索引. 3.唯一性太差的字段,比如 gender字段,就不应该创建索引. 4.不会出现在where条件之后的字段,不应该创建索引 ...

  5. Pytorch实战学习(七):高级CNN

    <PyTorch深度学习实践>完结合集_哔哩哔哩_bilibili Advanced CNN 一.GoogLeNet Inception Module:而为了减少代码的冗余,将由(卷积(C ...

  6. 用 go 实现多线程下载器

    本篇文章我们用Go实现一个简单的多线程下载器. 1.多线程下载原理 通过判断下载文件链接返回头信息中的 Accept-Ranges 字段,如果为 bytes 则表示支持断点续传. 然后在请求头中设置 ...

  7. 003. html篇之《表单》

    html篇之<表单> 一.结构 <form action="url" method="post" name=""> ...

  8. SCI、SSCI、EI、北大中文核心期刊、CSCD、CSSC、SCD、CSSCI 扩展版、计算机软件著作权

    https://zhidao.baidu.com/question/308484724.html SCI(科学引文索引).EI(工程索引).ISTP(科技会议录索引)是世界著名的三大科技文献检索系统, ...

  9. 2022强网拟态 WHOYOUARE

    2022强网拟态 WHOYOUARE 先说一下这个思路 由于禁用了__proto__所以我们可以通过constructor.prototype来绕过 之前一直不明白为什么是这样绕过的后来仔细研究了一下 ...

  10. repmgr部署和测试

    https://www.modb.pro/db/22029 https://blog.csdn.net/qq_34479012/article/details/125706815?app_versio ...