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 通过显示错误消息和事件消息来通知您操作成功以及操作失败.一部分错 ...
随机推荐
- react 项目实战(六)提取布局组件
重复代码是混乱的根源!,本篇文章我们来继续消灭重复代码. 目标 细心的同学应该能发现:每一个Page组件(/src/pages下的组件)的render方法都拥有相似的jsx结构,比如: render ...
- RAD 极速应用开发 Spring ROO 入门样例
官网 http://projects.spring.io/spring-roo/ Spring ROO in action ...
- SDUT--找朋友(BFS&&DFS)
找朋友 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 X,作为户外运动的忠实爱好者,总是不想呆在家里.如今,他想把死宅Y从家 ...
- Canny算法源码,欢迎交流
http://blog.csdn.net/jianxiong8814/article/details/1563109 http://blog.csdn.net/assuper/article/deta ...
- BZOJ 3041 水叮当的舞步
3041: 水叮当的舞步 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 120 Solved: 67[Submit][Status][Discuss ...
- 【codevs1306】广播操的游戏
求字符串内的非空子串的数量 后缀数组!!! #include<algorithm> #include<cstdlib> #include<cstring> #inc ...
- CSS总结01
1 CSS 的作用是? 2 如何引入 CSS 样式? 3 CSS 选择器的基本类型和复合选择器分别是? 4 字体.背景.列表和链接和鼠标的属性有哪些? 5 如何理解盒子模型? 6 浮动的方式有哪些,如 ...
- 【Android】Android输入子系统【转】
本文转载自:https://www.cnblogs.com/lcw/p/3506110.html Linux输入子系统回顾 1:为什么要回顾linux输入子系统?这个问题后面自然就知道了 1.linu ...
- ADT20 混淆编译
注意:一定要 android代码混淆,整了两天怎么也弄不去来,百度翻遍了也都是怎么配置cfg文件,怎么混淆成功的喜悦,我就气死了,怎么都不成功.真是气死了,不过功夫不负有心人,终究还是弄出来了. 不能 ...
- JSP-Runoob:JSP 结构
ylbtech-JSP-Runoob:JSP 结构 1.返回顶部 1. JSP 结构 网络服务器需要一个 JSP 引擎,也就是一个容器来处理 JSP 页面.容器负责截获对 JSP 页面的请求.本教程使 ...