您的位置:首页 > 其它

CodeForces 682B Alyona and Mex (题意水题)

2016-07-09 14:45 381 查看
题意:给定一个序列,你可以对这里面的数用小于它的数来代替,最后让你求,改完后的最大的序列中缺少的最小的数。

析:这个题,读了两个多小时也没读懂,要是读懂了,肯定能做出来。。。没什么可说的,就是尽量凑1 2 3 4 5。。。如果没有了,就输出。

代码如下:

#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];

int main(){
int n;
while(cin >> n){
for(int i = 0; i < n; ++i)  scanf("%d", &a[i]);
sort(a, a+n);
int cnt = 1;
for(int i = 0; i < n; ++i)
if(a[i] >= cnt) ++cnt;
printf("%d\n", cnt);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: