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. flask-基础篇03 RESTful

    一.起步: Flask-RESTful 是用于快速构建REST API 的Flask扩展 1.安装RESTful pip install flask-restful 2.Hello World示例 f ...

  2. tomcat 闪退 tomcat就是 找不到jre_home 

    Java环境变量 已经配置好了, 但是tomcat就是 找不到jre_home 所有就在 startup.bat 设置启动参数 SET JAVA_HOME=C:\Program Files\Java\ ...

  3. 3dsmax+vray5进行分布式渲染

    环境 我的两台电脑软件是一样的:win11 + 3ds max 2020 + vray5 update 2.2. 台式机1硬件是12900 + RTX 3080 Ti,台式机2硬件是12900KF + ...

  4. 「SOL」JOISC2021 解题报告

    JOIS(egment-Tree)C 1. 前言 很早之前教练让我们做这套题,我以为这套题应该挺简单,用几天的空余时间就能刷完,结果预想的短周期刷题变成了长周期刷题--(好像是整个团队里最后一个刷完的 ...

  5. 在C#中Release与Debug的区别小案例

    我们都听说过C#写的代码 Release通常会比Debug性能要好一点跑得快一些. 先普及一些相关基础知识: (1)在CLR中将对sbyte.byte.short.ushort.int.uint.ch ...

  6. ORACLE 失效索引重建

    -- 获取失效索引 SELECT * FROM USER_INDEXES WHERE TABLE_NAME IN ('表名') AND STATUS = 'UNUSABLE'; -- 重建语法alte ...

  7. VUE3 API之watch与watchEffect

    watch(source,callback,options) 官方术语:侦听一个或多个响应式数据源,并在数据源变化时调用所给的回调函数. watchEffect(effect,options) 官方术 ...

  8. Django操作redis

    一.环境安装 基本环境: Python环境:Python 3.8.16 Django环境:4.1 redis环境:参考搭建 https://www.cnblogs.com/yclh/p/1474233 ...

  9. Net Core 3.1 ONVIF 操控海康摄像头

    先给出实现的代码 https://github.com/lu1770/onvif-client.git 也可以通过安装包来使用功能 dotnet add package Onvif 基本用法 Agen ...

  10. (python)正则表达式

    # -*- coding: utf-8 -*- import re def test_dot(): """ . => 表示匹配任意字符 ""&q ...