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 ...
随机推荐
- VMware虚拟机下如何安装一个64位的win7系统
原文地址:http://www.xitongcheng.com/jiaocheng/win7_article_21001.html VMware虚拟机软件可以在一台电脑上运行多个操作系统,一些网友想在 ...
- SQL获取年月日方法
方法一:利用DATENAME 在SQL数据库中,DATENAME(datetype,date)函数的作用是从日期中提取指定部分数据,其返回类型是nvarchar.datetype类型见附表1. SEL ...
- Windows socket I/O模型 之 select(2)
在Windows socket I/O模型 之 select(1)中.我们仅仅是在console中简单的模拟了select的处理方法. 还有非常多特性不能改动.比方仅仅能写,不能读. 没使用线程.也 ...
- 矩形嵌套-记忆化搜索(dp动态规划)
矩形嵌套 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 有n个矩形,每个矩形能够用a,b来描写叙述,表示长和宽. 矩形X(a,b)能够嵌套在矩形Y(c,d)中当且仅 ...
- 服务管理-DHCP、NTP、SSH
DHCP协议的作用及原理 1.寻找server 当DHCP客户端第一次登陆网络的时候,也就是客户发现本机上没有任何ip资料设定,他会向网路发送一个dhcpdiscover封包.因为客户端还不知道自己属 ...
- java中使用opencv
Java + opencv学习:在Eclipse下配置基于Java的OpenCV开发环境 2016-04-08 17:43 6491人阅读 评论(0) 收藏 举报 分类: OpenCV学习(10) ...
- Presenting view controllers on detached view controllers is discouraged
本文转载至 http://www.xuebuyuan.com/2117943.html Presenting view controllers on detached view controllers ...
- 登录和注册(Js)的写法
今天在做小组项目的时候发现登录和注册的使用不是很熟,记录下来: <script> //弹出框中的css部分 input { font-family: Arial, sans-serif;} ...
- 九度OJ 1135:字符串排序 (排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1559 解决:807 题目描述: 先输入你要输入的字符串的个数.然后换行输入该组字符串.每个字符串以回车结束,每个字符串少于一百个字符. 如 ...
- define tensorflow and run it
import tensorflow as tf a, b, c, d, e = tf.constant(5, name='input_a'), tf.constant(6, name='input_b ...