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. MavenDependencies 报错缺少jar包

    1.首先看你的工程是否是maven项目,如果不是,则先转换为maven项目. 如果已经是maven项目了,maven的依赖库无法添加,则移步2: 2.项目右键,选择maven,然后子菜单,选择&quo ...

  2. VS+QT创建的项目 UI界面更新控件,代码里识别不到

    1.如果安装了小番茄,看下自己的小番茄的设置里,source of C/C++ content需要选择 Default Intellisense,选择visual assist是识别不到的,具体是为什 ...

  3. 使用fopen,fscanf等函数报安全性问题的错误,unsafe...

    方法一:项目-属性-C/C++-预处理器定义,添加_CRT_SECURE_NO_WARNINGS. 方法二:使用fopen_s,fscanf_s等安全函数.

  4. 【GROMACS】分子动力学模拟①——环境搭建

    系统环境 Win11 22H2 企业版 开启虚拟化.window subsystem for liunx等虚拟机相关的功能 应用商店中安装WSL2 安装步骤 打开Ubuntu,输入sudo apt f ...

  5. 南大ics-pa/PA1.1过程及感想

    1.1 一.在红白模拟器上运行超级马里奥游戏 1.将游戏rom文件mario.nes移至~/ics2022/fceux-am/nes/rom文件下,并回到~/ics2022/fceux-am下执行ma ...

  6. MargeSort

    归并排序(Merge Sort)是建立在归并操作上的一种有效,稳定的排序算法,该算法是采用分治法(Divide and Conquer)的一个非常典型的应用.将已有序的子序列合并,得到完全有序的序列: ...

  7. vue+vant打包,vue+vant-ui小程序,微信支付

    微信JS支付代码_前端调用微信支付接口 其实参照官方文档一步一步操作不是很难,但很多人在签名这个地方就总是出现问题,因为文档中签名时使用的字段大小写时错误的....好坑啊!!然而PHP版本的代码官方有 ...

  8. 01_Node的版本管理

    Node的版本管理工具 常见的node的版本管理工具有两种N.NVM 但是他们有一个致命的问题就是不支持Windwos 但是NVM延申了一个nvm-windows的版本,他就可以很好的支持window ...

  9. 【PS】PS如何删除图片中的白字

    [PS]PS如何删除图片中的白字 首先打开ps,然后导入要操作的图片,接着选择左边工具栏中的魔棒工具. 对所要操作的文字进行框选,可以按住shift键进行连续操作 点击上方工具栏中的选择 | 修改 | ...

  10. python日志篇-基础版

    对常用python日志语法做记录,方便以后重复使用 print内容记录到文件: #!/usr/bin/env python # -*- coding: utf-8 -*- ##____________ ...