Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
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
Hint
题意
给你一个序列,然后这个序列可以交换任意两个数的位置,以及减小若干个数的大小。
然后问你这个序列的mex最大能够是多少。
题解:
排序扫一遍,太水了……
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,a[maxn];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
int level=0;
for(int i=1;i<=n;i++)
{
if(a[i]>level)
level++;
}
cout<<level+1<<endl;
}
最新文章
- Hibernate ManyToOne, OneToMany的理解
- 使用后缀数组寻找最长公共子字符串JavaScript版
- 双栈排序(codevs 1170)
- shell 命令遇到的一些问题
- Textview下划线注册用户跳转实现
- sourcetree使用问题汇总
- Linux Shell脚本读写XML文件
- 对同一元素设置overflow-x:hidden,overflow-y:visible;属性值不生效
- 中文变英文字母(ios)
- [转] HBase的特征和优点
- Asp.Net 控件radio 的简单使用
- 编程内功修炼之数据结构—BTree(一)
- 图片延时加载jquery.inview.js用法详解
- Angular 非父子组件间的service数据通信
- hihoCoder 1015 KMP算法
- Springboot项目配置druid数据库连接池,并监控统计功能
- python之函数对象、函数嵌套、名称空间与作用域、装饰器
- C#中将ListView数据导出为excel(转载)
- box-shadow比较美观的阴影
- Redis内存分析方法
热门文章
- linux kernel的中断子系统之(三):IRQ number和中断描述符【转】
- O_NONBLOCK与O_NDELAY有何不同?
- aarch64_m1
- TableView 的那些坑
- Focal Loss笔记
- go 切片的 插入、删除
- DevExpress CxGrid 隐藏 Drag a column header to group by that column
- c++实现二叉树的非递归创建以及非递归先序、中序、后序遍历
- MyBatis的动态插入语句(经常报‘无效的列类型’)
- 批处理命令篇--配置免安装mysql