CF1165B Polycarp Training

2023-05-16

原题链接
题目描述
Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 11 problem, during the second day — exactly 22 problems, during the third day — exactly 33 problems, and so on. During the kk -th day he should solve kk problems.

Polycarp has a list of nn contests, the ii -th contest consists of a_ia
i

problems. During each day Polycarp has to choose exactly one of the contests he didn’t solve yet and solve it. He solves exactly kk problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least kk problems that Polycarp didn’t solve yet during the kk -th day, then Polycarp stops his training.

How many days Polycarp can train if he chooses the contests optimally?

输入格式
The first line of the input contains one integer nn ( 1 \le n \le 2 \cdot 10^51≤n≤2⋅10
5
) — the number of contests.

The second line of the input contains nn integers a_1, a_2, \dots, a_na
1

,a
2

,…,a
n

( 1 \le a_i \le 2 \cdot 10^51≤a
i

≤2⋅10
5
) — the number of problems in the ii -th contest.

输出格式
Print one integer — the maximum number of days Polycarp can train if he chooses the contests optimally.

题意翻译
Polycarp想要在另外一场比赛中训练,第一天他可以解决一个问题,第二天可以解决两个,以此类推,在第KK天他可以解决KK个问题

Polycarp有NN场比赛,第ii场比赛有aa_i
i

个问题,每一天他可以选择其中一个他尚未解决的比赛解决,但是要求a_ia
i

\ge≥KK,如果在第KK天尚未解决的比赛中没有大于等于KK的比赛,则Polycarp终止训练。

那么Polycarp最多能训练多少天呢?

输入输出样例
输入 #1复制
4
3 1 4 1
输出 #1复制
3
输入 #2复制
3
1 1 1
输出 #2复制
1
输入 #3复制
5
1 1 1 2 2
输出 #3复制

思路
就是所有比赛的题目总数从小到大排,然后定义一个K,然后如果当前比赛题目的数量大于K,那么k++.
最后输出k-1;

错误原因
因为一个比赛只可以打一次,所以直接往后遍历就行了,之前看成了只要题目数够就可以打;

错误代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,num[200005]={0};
	map<int,int> res;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
	}
	int k=0;
	num[n]=200006;
	while(1)
	{
		sort(num,num+n);
		int flag=lower_bound(num,num+n,k)-num;
		//cout<<num[flag]<<endl;
		if(num[flag]==200006)
		{
			break;
		}
		else
		{
			num[flag]-=k;
		}
		k++;
	}
	cout<<k-1;
	return 0;
}

正确代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,num[200005]={0};
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>num[i];
	}
	sort(num,num+n);
	int ans=1;
	for(int i=0;i<n;i++)
	{
		if(num[i]>=ans)
		{
			ans++;
		}
	}
	cout<<ans-1; 
	return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CF1165B Polycarp Training 的相关文章

  • P1002 [NOIP2002 普及组] 过河卒

    题目描述 棋盘上 A 点有一个过河卒 xff0c 需要走到目标 B 点 卒行走的规则 xff1a 可以向下 或者向右 同时在棋盘上 C 点有一个对方的马 xff0c 该马所在的点和所有跳跃一步可达的点称为对方马的控制点 因此称之为 马拦过河
  • 3D Slicer源代码编译与调试

    2019 11 12 参考以下链接 xff1a https www slicer org wiki Documentation Nightly Developers Build Instructions Windows 需要注意的有 xff
  • DSP Group, Inc. <DSPG>

    公司官网 xff1a DSP Group Leading global provider of wireless chipset solutions About DSP Group DSP Group Inc NASDAQ DSPG is
  • 数组或对象指定下标赋值及下拉数据转化

    一 数组指定下标赋值 span class token variable let span span class token variable myarr span span class token punctuation 61 span
  • XMOS 开发探索3-麦克风拾音

    date 2021 03 29 XMOS 评估板型号 xff1a XUF216 512 TQ128 C20 实现麦克风拾音 xff0c 并从耳机输出声音 xff0c 官方网站上的一个demo xff1a Application Notes
  • 安装ubuntu系统中磁盘分区

    硬件 xff1a vostro 1450 xff0c 本身有一块机械硬盘HDD xff08 500G xff09 加了一块固态硬盘SSD xff08 120G xff09 xff0c 组成HDD 43 SSD双硬盘 目的 xff1a SDD
  • win7+ubuntu双系统 -- ubuntu无法启动

    硬件 xff1a vostro 1450 xff0c 本身有一块机械硬盘HDD xff08 500G xff09 加了一块固态硬盘SSD xff08 120G xff09 xff0c 组成HDD 43 SSD双硬盘 目的 xff1a SDD

随机推荐

  • Xshell 和 Xftp 学校免费版

    Xshell 和 Xftp 家庭 学校免费版下载地址 xff1a 家庭 学校免费 NetSarang Website 填写姓名和邮箱 xff0c 下载免费版 xff0c 会发送邮件到邮箱 45M 安装完成并打开 xff1a 39M 用来传输
  • putty pscp psftp 三件套

    官网地址 xff1a https www chiark greenend org uk sgtatham putty https www chiark greenend org uk sgtatham putty latest html p
  • win10远程连接win7电脑 -- 局域网实现

    本次 xff1a 使用 windows自带 的 远程桌面连接 xff08 ok xff09 另外 xff1a 向日葵 远程软件更方便 xff0c 可以直接在公网使用 xff08 get xff09 TeamViewer 远程软件越来越不好用
  • scp 报错: Permission denied, please try again(publickey,password)

    修改密码后导致报错 Permission denied please try again publickey password 修改 etc ssh sshd config 中 PermitRootLogin yes 修改为yes 重启服务
  • 关闭树莓派的电源指示灯和状态指示灯

    在命令行输入一下指令 xff1a echo 0 sudo tee sys class leds led0 brightness 状态指示灯 范围 0 255 echo none sudo tee sys class leds led0 tr
  • 虚拟机安装Vmware Tools复制文件,共享文件

    目标1 xff1a 虚拟机安装Vmware Tools工具 先看下VMware版本 xff1a 首先 xff0c 将CD DVD切换到物理驱动器 xff1a 点击菜单 虚拟机 M 34 安装VMware Tools xff0c 虚拟DVD中
  • xavier上如何挂载SD卡

    參考博客 Jetson AGX Xavier避坑指南 六 挂载 SD 卡 zxxRobot的博客 CSDN博客 xavier挂载sd卡 AGX Xavier挂载SD卡 Bungehurst CSDN博客 Nvidia Jetson AGX
  • NXP-LPC1768起步之开发环境搭建与GPIO

    1 环境搭建 本工程使用ARM公司MDK414 低版本的可能会导致在MDK中无法下载调试程序 仿真器使用SEGGER公司JlinkV7 首先新建工程GPIO xff0c 选择路径保存 xff0c 然后会出现选择芯片界面 然后确定 xff0c
  • docker 修改默认存储路径的方法

    在xavier上使用docker时 由于空间不足 无法继续工程 几种修改 Docker 镜像默认存储位置的方法 墨天轮 使用方法一 使用软链接的方式 容器的存放位置在 var lib docker 默认存放位置 sudo docker in
  • linux下usb无线网卡对比

    2021年12月23日 冬月二十 xff0c 天晴 xff0c 微风 一 使用场景 1 xff0c 由于软件开发需要用到linux系统 xff0c 嵌入式设备nvidia xavier没有无线网卡 xff0c 需要自购 2 xff0c 另外
  • ubuntu 18.04.6官方下载地址

    Enterprise Open Source and Linux Ubuntu 进入界面 xff1a Download Ubuntu Desktop Download Ubuntu 点击 xff1a see our alternative
  • ubuntu误删 /var/lib/dpkg

    折腾了一个小时 Deepin Debian Ubuntu恢复误删除的 var lib dpkg 学亮编程手记的博客 CSDN博客 https jingyan baidu com article fc07f98946cd3e12fee5196
  • E: Could not get lock /var/lib/dpkg/lock

    dpkg error dpkg frontend is locked by another process dpkg error dpkg frontend is locked by another process 白蛇仙人的博客 CSDN
  • 树莓派安装花生壳软件 phddns ,没有显示SN码

    树莓派型号 xff1a Pi4B 2G 树莓派系统版本 xff1a uname a Linux raspberrypi 5 10 103 v7l 43 1529 SMP Tue Mar 8 12 24 00 GMT 2022 armv7l
  • E: Could not get lock /var/lib/dpkg/lock

    ubuntu安装软件时 xff0c 经常出现下面错误 xff1a sudo apt get install E Could not get lock var lib dpkg lock open 11 Resource temporaril
  • shell 脚本常用命令,音频提取、格式转换、切割

    实现一下功能 xff1a 1 xff0c mp4 视频文件提取 wav xff0c pcm xff1b 2 xff0c wav 切割为每段30s 的音频 xff1b 3 xff0c wav 切割后的音频转换为 pcm xff0c ffmpe
  • Apache Options Indexes FollowSymLinks详解

    如果该虚拟目录下没有 index html xff0c 浏览器也会显示该虚拟目录的目录结构 xff0c 列出该虚拟目录下的文件和子目录 如何禁止 Apache 显示目录列表呢 xff1f 要禁止 Apache 显示目录结构列表 xff0c
  • 大恒工业相机+opencv开发经历

    遇到的问题 xff1a 1 打开Daheng Galaxy Viewer x64 没有图像 由于对工业相机不熟悉 xff0c 原因是没有安装镜头 xff0c 安装镜头后可以正常使用 xff0c 否则只有白色或黑色 xff0c 用手指靠近镜头
  • Backtrace in Android

    Backtrace in Android 96 Tsing2015 0 7 2016 02 28 23 03 字数 33 阅读 2491评论 8喜欢 4 libscorkscrew so在android 5 0之后已经没有了 xff0c 之
  • CF1165B Polycarp Training

    原题链接 题目描述 Polycarp wants to train before another programming competition During the first day of his training he should