Ivan and Powers of Two CodeForces - 305C(set)
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.
Input
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.
Output
Print a single integer — the answer to the problem.
Examples
Input
4
0 1 1 1
Output
0
Input
1
3
Output
3
Note
In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.
In the second sample you need to add numbers 20, 21, 22.
在这里充分用到了set去重的功能。要知道2^n +2^n= 2^(n+1).先输入x,如果发现x在集合里面,就要把x去掉,然后将x+1存到里面,如果x+1也在里面的话,就去掉将x+2存到里面,这是一个循环的过程。代码如下:
#include<iostream>
#include<cstring>
#include<set>
#include<cmath>
using namespace std;set<int>num;
int n;int main()
{while(scanf("%d",&n)!=EOF){int a;num.clear(); int maxn=-0x3f3f3f3f;while(n--){scanf("%d",&a);while(num.count(a)){num.erase(a);a++;}num.insert(a);maxn=max(maxn,a);}printf("%d\n",maxn+1-num.size());}}
努力加油a啊,(o)/~
Ivan and Powers of Two CodeForces - 305C(set)相关推荐
- E - Code Parsing CodeForces - 255B(思维)
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly ...
- Board Moves CodeForces - 1353C(数学)
题意: 有一个 n×n 的矩阵(n 为奇数),每个矩阵单元有一个物品,每次操作你可将一个单元里的一个物品移动到该单元周围的八个单元里,问最后只有一个单元有物品的情况下,最少要多少次操作? 题目: Yo ...
- By Elevator or Stairs? CodeForces - 1249E(动态规划)
题意 n层楼,a[i] (0<i<n)表示从 i 楼到 i + 1 楼走楼梯的时间,b[i] (0<i<n)表示从 i 楼到 i + 1 楼乘电梯的时间,其中每一次乘电梯需要等 ...
- Codeforces #594 (Div. 1) A. Ivan the Fool and the Probability Theory(DP)
原题链接:https://codeforces.com/contest/1239/problem/A 大佬用来热身的小题 而我却迟迟想不出来 当n和m都为1的时候显然只有两种情况 当n为1,m不为1的 ...
- codeforces 133A(HQ9+) Java
codeforces 字符串水题 输入的字符串中是否含有 H.Q.+ 这三种字符. 方法一: import java.io.BufferedReader; import java.io.InputSt ...
- Berzerk CodeForces - 787C (BFS)题解
Codeforces Round #406 (Div. 2)-- A - Berzerk A. Berzerk time limit per test4 seconds memory limit pe ...
- Codeforces 989C (构造)
传送门 题面: C. A Mist of Florescence time limit per test 1 second memory limit per test 256 megabytes in ...
- Task On The Board CodeForces - 1367D(思维)
Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This strin ...
- Generate a String CodeForces - 710E(dp)
zscoder wants to generate an input file for some programming competition problem. His input is a str ...
最新文章
- 获取族_批量添加族参数(上)
- Java:IDEA下使用JUNIT
- 多stream_基础之Lambda和Stream的邂逅
- chrome扩展之4(终结篇):一步步跟我学开发一个表单填写扩展
- java jsfl是什么_java基础之IO2
- 2018北京ICPC H. Approximate Matching(AC自动机+DP)
- swagger连接mysql数据库_一键生成数据库文档,堪称数据库界的Swagger,有点厉害!...
- python安卓脚本精灵使用教程_【按键精灵教程】自动安装apk还可以这么用!
- 【算法】并查集(Java)
- M27C64A引脚说明
- 给别人打电话显示用话提醒服务器,打电话给对方但提示已启用来电提醒功能,是怎么回事...
- excel 中vb组合框_Excel 2013中的工作表组合框问题
- 基于Android技术的物联网应用开发
- U8-固定资产月末结账报错:BOF或EOF中有一个是真
- 前端:计算滚动条距底部多远(距离底部的百分比)
- Ubuntu20.04突然丢失网络时恢复的办法
- 无法运行宏,可能是因为该宏在此工作簿中不可用,或者所有的宏都被禁用的解决方法...
- 三分钟学会数据库, replace() 替换
- VC无负担实现XP风格界面
- 从南宋临安城武林夜市到二维码收款,IoT 语音播报音箱的普及
热门文章
- oracle 物理表,【查询Oracle表实际物理使用大小】
- java iconsolefactory_java – 如何设置IOConsole的Caret
- 计算机考试用远程桌面,职称计算机考试:教你体验XP远程桌面多用户登录
- django 按钮的样式_【实战演练】Python+Django网站开发系列11-成绩查询与成绩录入...
- c++ ifstream 文件不结束_C/C++编程笔记:你不知道的windows保存文件的坑
- recyclerview的数据刷新(下拉刷新和自动加载更多)以及添加提示语(例如:“数据已加载完毕”)
- css钢铁侠视角,CSS3 Iron Man 钢铁侠肖像
- DOF和MultiSwitch的使用
- Android开发之最简单的布局点击Tab和Fragment切换源码(特别适合初学者)
- Android 百度地图之全局搜索周边搜索全国搜索城市路线规划(升级版附源码)