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 通过显示错误消息和事件消息来通知您操作成功以及操作失败.一部分错 ...
随机推荐
- Ckeditor通过Ajax更新数据
之前在表单中对ckeditor的赋值就直接是 $("#theadEditor").val(result); 而如今我想通过点击不同选项来使用Ajax在后台訪问数据.对ckedito ...
- DataNucleus之JDO操作演示样例
JDO(Java Data Object )是Java对象持久化的新的规范.也是一个用于存取某种数据仓库中的对象的标准化API. 注意JDO是一种规范,而不是一个产品.而DataNucleus正是实现 ...
- hdu 5001 概率DP 图上的DP
http://acm.hdu.edu.cn/showproblem.php?pid=5001 当时一看是图上的就跪了 不敢写,也没退出来DP方程 感觉区域赛的题 一则有一个点难以想到 二则就是编码有 ...
- [英语学习]微软面试前英语集训笔记-day 1
最近有机会参加微软面试前的英语集训. 第一天是由wendy老师主讲.热场题目是介绍你自己.包括你的姓名,家庭hobby,爱好,专业,学校,工作经历等等. 接下来的主题是friendship.给我印象较 ...
- javascript里的prototype
在javascript中,prototype是函数的一个固有属性,其他对象,比如字符串什么的,并没有这个属性. 这个属性做什么用呢? 1.用于该函数的所有实例进行共享 比如,共同的属性,共同的方法.类 ...
- 通过shell脚本批处理es数据
#!/bin/sh [按照指定的域名-website集合,遍历各个域名,处理url] #指定待删除的变量集合 arr=(6.0) cur="`date +%Y%m%d%H%M%S`" ...
- redis 的部分配置
linux 安装: yum install redis 修改redis配置: 配置文件位于/etc/redis.conf. 作为守护进程运行(默认no) # 默认情况下 redis 不是作为守护进程运 ...
- Oracle 11g密码过期问题及解决方案
问题: 在自用的一个系统里,连接的是本地自建的一个数据库.用sqldeveloper登录数据库.提示如下图: 提示:密码过期 解决方案: 密码过期一般存在两种可能: 由于Oracle中默认在defau ...
- Ubuntu新版中javascript-common.conf害死人啊
自动把javascript目录映射到系统的/usr/share 下面了,删掉对应的软链接再重启就好了
- mac 下idea光标问题
可以使用 fn + i 解决此问题