Codeforces Round #358 (Div. 2) B. Alyona and Mex
来源:互联网 发布:阿里云扩容数据盘 编辑:程序博客网 时间:2024/05/22 23:08
B. Alyona and Mex
题目连接:
http://www.codeforces.com/contest/682/problem/B
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 every 1 ≤ 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
5
1 3 3 3 6
Sample Output
5
题意:给你一个序列,可以变换两个数的位置,也可以将一个数变为比其本身小的数,问最后形成的序列的最大值+1
思路:排序,然后扫一遍就可以了
ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<set>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 1010000#define LL long long#define ll __int64#define INF 0xfffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)#define eps 1e-8using namespace std;ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}//headint a[MAXN];int main(){ int n;scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); int ans=0,num=1; for(int i=0;i<n;i++) { if(a[i]<num) ans++; else num++; } printf("%d\n",num); return 0;}
- Codeforces Round #358 (Div. 2) B. Alyona and Mex
- Codeforces Round #358 (Div. 2) B. Alyona and Mex
- Codeforces Round #358 (Div. 2) B. Alyona and Mex
- Codeforces Round #358 (Div. 2) B. Alyona and Mex【水题】
- Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
- Codeforces Round #358 (Div. 2) B Alyona and Mex(水题)
- Codeforces Round #358 (Div. 2) -- B. Alyona and Mex (思路水题)
- Codeforces Round #381 (Div. 2)C - Alyona and mex
- Codeforces Round #381 (Div. 2) C. Alyona and mex
- Codeforces Round #381 (Div. 2)C. Alyona and mex
- Codeforces Round #381 (Div. 2) Alyona and mex
- Codeforces Round #381 (Div. 2)-C. Alyona and mex
- Codeforces 358 . B Alyona and Mex
- Codeforces Round #381 (Div. 1) A. Alyona and mex
- Codeforces Round #381 (Div. 2) B. Alyona and flowers
- Codeforces Round #209 (Div. 2) B. Alyona and flowers
- Codeforces Round #381 (Div. 2) C. Alyona and mex(思维)
- Codeforces Round #381 (Div. 2) C. Alyona and mex(模拟)
- java.lang.NoClassDefFoundError:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- java设计模式
- 换头像的功能实现
- JS实现密码加密(base64, md5, sha1)
- android官方适配
- Codeforces Round #358 (Div. 2) B. Alyona and Mex
- canvas globalCompositeOperation
- 关于UITextField的左移问题
- MVP 与MVC 的区别
- lintcode ----最长连续序列
- Android Canvas编程:对rotate()和translate()两个方法的研究
- 负数在计算机中存储方式,原码,补码,反码概念
- c++ STL::String::Compare (_Buf内容一致,compare不相等)
- js面向对象编程