B - Alyona and Mex
Description
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.
Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.
Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array.
The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.
Output
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
Sample Input
Input5
1 3 3 3 6Output5Input2
2 1Output3
题意:
给出n个元素,元素可交换或减小,求最终缺少的最小正整数的最大值(mex)。
仔细观察我们不难看出当n个元素为从1~n递增时mex取最大值,如n=5时,1,2,3,4,5,mex取最大值6。所以我们就将数列尽量接近连续递增数列。
如1 3 3 3 6可改为1 2 3 3 4则取最大值mex为5。
附AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int MAX=; int a[MAX]; int main(){
int n;
while(cin>>n){
for(int i=;i<n;i++){
cin>>a[i];
}
int ans=;
sort(a,a+n);//排序
for(int i=;i<n;i++){
if(a[i]>=ans)//注意等于
ans++;
}
cout<<ans<<endl;
}
return ;
}
B - Alyona and Mex的更多相关文章
- Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)
C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative i ...
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- Codeforces Round #381 (Div. 1) A. Alyona and mex 构造
A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...
- Codeforces Round #358 (Div. 2)B. Alyona and Mex
B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CodeForces 682B Alyona and Mex (排序+离散化)
Alyona and Mex 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/B Description Someone gave ...
- Alyona and mex
Alyona and mex time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...
- CF | Alyona and Mex
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyon ...
- Codeforces Round #381 (Div. 2)C Alyona and mex
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be ...
随机推荐
- 不能hadoop-daemon.sh start datanode, 显示 错误: 找不到或无法加载主类 ”-Djava.library.path=.home.hadoop.apps.hadoop-2.6.4.lib”
这两行代码是用来解决一个Hadoop,32位和64位不兼容的警告的,(这个警告可以忽略) 这两行加到mini2~min4后, export HADOOP_COMMON_LIB_NATIVE_DIR=$ ...
- python--函数程序分析
写函数,用户传入修改的文件名,与要修改的内容,执行函数,完成整个文件的批量修改操作 import os #加载模块 def xiu(a,b,c): #三个接受值的形参 f = open(a,encod ...
- byte数组和文件的相互转换
/** * 获得指定文件的byte数组 */ private byte[] getBytes(String filePath){ byte[] buffer = null; try { File fi ...
- ubuntu环境eclipse配置
ubuntu环境eclipse配置 首先下载Eclipse和JDK: 然后将上边两个压缩包解压到安装文件夹(如;/home/linux/softwares/java).然后配置/etc/profile ...
- ecshop购买记录(近期成交数量)显示历史记录
默认只显示最近30天内的销售记录, 按照下面方法修改 就可以显示所有的了 打开 /includes/lib_insert.php 文件 找到下面代码,将之删除即可,一共有两处,都要删除. AND ' ...
- JAVA RMI远程方法调用简单实例(转载)
来源:http://www.cnblogs.com/leslies2/archive/2011/05/20/2051844.html RMI的概念 RMI(Remote Method Invocati ...
- OpenCV 入门示例之一:显示图像
前言 本文展示一个显示图像的示例程序,它用于从硬盘加载一副图像并在屏幕上显示. 代码示例 // 此头文件包含图像IO函数的声明 #include "highgui.h" int m ...
- ABAP DEMO-2018
sap Program DEMO 介绍 Program Description BALVBT01 Example SAP program for displying multiple ALV repo ...
- jquery特效(8)—倒计时
最近公司在做一个答题的小游戏,每道题可以有20秒时间作答,超过时间就要给出相应的提醒,由于20秒时间太长,不适合做GIF动态图,下面来看一下我写的5秒倒计时的测试程序结果: 一.主体程序: <! ...
- FFmpeg滤镜代码级分析
http://blog.chinaunix.net/uid-26000296-id-3322071.html 前一篇文章<为FFmpeg添加自定义滤镜>详细讲述了FFmpeg的滤镜添加步骤 ...