codeforces_305C_STLset
0.5 seconds
256 megabytes
standard input
standard output
Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0)need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0).
Help Ivan, find the required quantity of numbers.
The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an(0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an.
Print a single integer — the answer to the problem.
4
0 1 1 1
0
1
3
set数据结构的应用,
#include<iostream>
#include<cstdio>
#include<set>
using namespace std; set<int> s; int main()
{
int n,maxn=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
int num;
scanf("%d",&num);
while(s.count(num))
{
s.erase(num);
num++;
}
s.insert(num);
maxn=max(maxn,num);
}
printf("%d\n",maxn-s.size()+);
return ;
}
codeforces_305C_STLset的更多相关文章
- Team Foundation 中的错误和事件消息
Visual Studio Team System Team Foundation 中的错误和事件消息 Team Foundation 通过显示错误消息和事件消息来通知您操作成功以及操作失败.一部分错 ...
随机推荐
- [Qt总结篇]终端远程升级client
环境: QT4.8.5 for Windows(Qt Creator+MinGW) 一.写在前面: 1.深度:鉴于C/C++的功底还远远不足,个人主要精力还是学习C/C++,所以没打算继续深入研究Qt ...
- HDU 1047 Integer Inquiry 大数相加 string解法
本题就是大数相加,题目都不用看了. 只是注意的就是HDU的肯爹输出,好几次presentation error了. 还有个特殊情况,就是会有空数据的输入case. #include <stdio ...
- 【Struts2五】ValueStack以及ognl表达式二(经常使用标签)
Ognl经常使用标签: 1.s:debug 假设把该标签放入到s:iterator中能够看到当前正在迭代的元素的状态 2.s:property 1.输出 ...
- iOS CMSampleBuffer deep copy
extension CVPixelBuffer { func copy() -> CVPixelBuffer { precondition(CFGetTypeID(self) == CVPixe ...
- web 开发之js---js 实现文本高亮
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head ...
- DSPC6748中某问题的解决方式
因为之前没有做过DSP相关的开发,属于菜鸟中的菜鸟.出现故障后.不知道从哪方面来解决这些小问题. 开发环境:CCS5.5.0 开发板:TI公司的TMS320C6748 问题: 控制台出现初始化结束后多 ...
- leetcode第一刷_Search in Rotated Sorted Array
旋转数组的查找问题.从头開始扫一遍.O(N)的复杂度,一般也能过,甚至先排序下面,再二分都能过.只是这道题的目的当然不在于此. 想一下旋转之后对我们的查找产生了什么影响.假设没旋转过,我们直接比較ta ...
- go11---方法method
package main /* 方法method Go 中虽没有class,但依旧有method 通过显示说明receiver来实现与某个类型的组合 只能为同一个包中的类型定义方法 Receiver ...
- sql 2005 win7 64 数据引擎
有个箭头,下拉,选择服务器名(就是本机的名称),如果没有就选择浏览更多,看能搜索出不还没的话就手动输入localhost
- ROUND function and arithmetic overflow
遇到如下错误 Arithmetic overflow error converting expression to data type numeric. ), ); https://stackover ...