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动画建模设计工具,是 ...
随机推荐
- SSL certificate problem: unable to get local issuer certificate 错误解决
终端报了如下错误git SSL certificate problem: unable to get local issuer certificate 这个问题是由于没有配置信任的服务器HTTPS验证 ...
- CC1101RGPR学习笔记:工作原理简单入门
众所周知,在IOT的市场应用中,从通信协议细分的话,有SUB-1G,2.4G,3G, 4G,以及最新推出的5G,虽然5G通信协议已经在崭露头角,但是不同的通信协议在不同的应用领域之中还是占据着一定的重 ...
- xrdp 启动分析
前言:xrdp模块说明 参考文档:xrdp-genkeymap man page - xrdp - System Administration (mankier.com) xrdp:远程桌面协议 (R ...
- VS2015+QT5.10项目中文乱码
解决:文件-高级保存选项,选择utf-8编码.
- VirtualBox上使用qemu和busybear搭建RISCV环境
Step 1:安装一些编译riscv需要的库: sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr ...
- firefox 利用 Selenium IDE 对 DBackup 进行自动化测试
今天看<编写可维护的JavaScript>的时候有一章是专门讲 Selenium 对 JavaScript 进行自动化测试的. 在了解了 Selenium 的强大之后,动手试验了一下 fi ...
- nginx 可视化配置平台
nginx是一个高性能的HTTP和反向代理服务器.在部署项目中,经常会用到,但是配置是比较麻烦的,很容易出错,今天大叔给大家推荐一个非常好用的可视化平台 -- nginx-gui. 项目功能 配置管理 ...
- (已解决)nginx+tp,怎么设置 省略index.php的url访问。
打开vhosts.conf,在localhost / {}里面加入下面的代码: if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 ...
- Access 时间查询 与 SQL SERVER 不一样的几个地方
最近用到了ACCESS 数据库 ,与之前用SQL SERVER 还是有点区别的. 1. 时间 之间 用 # 连接 如下: public static string GetUserInfo(stri ...
- Day_1(并查集朋友圈、字典序排序)
1.并查集 朋友圈:找出最多的一个圈子内有多少用户! id[](表示当前节点的父节点) nodeNum[] (表示当前节点为根的那一组节点数量) import java.util.Scanner; / ...