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 ...
随机推荐
- BUCK电路工作原理
Buck电路,也称呼为DC_DC Buck型降压开关电源电路,这种电路结构实际应用也是很多的,电路拓扑结构看下图: 电路中,Q1是开关管,D1是续流二极管,L1就是问题中提到的这个电感器.C1就是问题 ...
- web前端面试系列 - 数据结构(两个栈模拟一个队列)
一. 用两个栈模拟一个队列 思路一: 1. 一个栈s1作为数据存储,另一个栈s2,作为临时数据存储. 2. 入队时将数据压人s1 3. 出队时将s1弹出,并压人s2,然后弹出s2中的顶部数据,最后再将 ...
- POI-----POI操作Excel-4、字体
- kubernetes之常见故障排除(一)
系列目录 由由种种原因,在安装或者使用kubernetes的过程中,可能会遇到各种各样的问题.本篇按照官网的介绍罗列出一些常见的故障,以帮助快速解决一些常见的错误. 安装赛程中出现ebtables o ...
- vue 路由组件不重新加载
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 怎样高速编译mediatek\operator以下代码
mediatek\operator以下有单独的apk.也有overlay的数据,单独的apk会配置anroid.mk,找到相应的路径直接build. 假设是overlay,则编译原来应用的路径,比如 ...
- Python之Pandas库常用函数大全(含注释)
前言:本博文摘抄自中国慕课大学上的课程<Python数据分析与展示>,推荐刚入门的同学去学习,这是非常好的入门视频. 继续一个新的库,Pandas库.Pandas库围绕Series类型和D ...
- android lanchmode
http://www.cnblogs.com/xiaoQLu/archive/2012/07/17/2595294.html http://www.cnblogs.com/lwbqqyumidi/p/ ...
- 【BZOJ2625】[Neerc2009]Inspection 最小流
[BZOJ2625][Neerc2009]Inspection Description You are in charge of a team that inspects a new ski reso ...
- 在MFC中使用大漠插件
打开Class Wizard,Add Class...->MFC Class From TypeLib... File->Location->>> Finish-> ...