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 通过显示错误消息和事件消息来通知您操作成功以及操作失败.一部分错 ...
随机推荐
- 基于MFC的一个简单计算器
写一个简单的计算器并不是什么很难的事,主要目的是要通过这个程序来学习和分析其中的核心算法.这个简易计算器的核心部分就是对输入的表达式的正确性判断与求值,其中包括对表达式的解析.中缀表达式转后缀表达式. ...
- eclipse中j2ee(struts2)部署及相关问题释疑
1.eclipse中进行web项目开发时.部署的时候和利用myeclipse部署时有非常大不同,由于在myeclipse的工具栏中有一个部署button.而且在myeclipse的preference ...
- CI知识:GitLab
Gitlab简介 GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务. 可通过Web界面进行访问公开的或者私人项目.它拥有与Github类似的 ...
- MVC4中给TextBoxFor设置默认值和属性(同时设置js事件)
例如:(特别注意在设置初始值的时候 Value 中的V要大写) @Html.TextBoxFor(model => model.CustomerCode, new { Value=" ...
- 万一的Delphi消息教程
http://www.cnblogs.com/del/category/134064.html
- kendo datepicker汉化
kendo grid 支持多语言,包括的语言有非常多种.一般默认情况是使用en,可是对于国内市场的话我们须要使用汉字.不墨迹了. <link href="http://cdn. ...
- H264 介绍[1]
频编解码技术有两套标准,国际电联(ITU-T)的标准H.261.H.263.H.263+等:还有ISO 的MPEG标准Mpeg1.Mpeg2.Mpeg4等等.H.264/AVC是两大组织集合H.263 ...
- bzoj 2067 [ Poi 2004 ] SZN —— 二分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2067 问题1:贪心考虑,应该是每个点的儿子尽量两两配对,如果剩一个就和自己合并向上,所以 a ...
- ELK Stack总结
目录 ELK Stack 介绍 Elasticsearch 概念1(基础) CRUD基本用法 概念2(文本解析器) 查询 分析/聚合 概念3(架构原理的补充) Logstash基础 Kibana的数据 ...
- bzoj 1704: [Usaco2007 Mar]Face The Right Way 自动转身机【贪心+差分】
首先O(n^3)的贪心很好想,就是枚举k然后从前往后扫,扫到反就翻转区间 然后考虑优化掉翻转区间维,就是搞成差分的形式,在翻转区间的尾部打上标记,再用一个变量维护当前的翻转次数,加到当前状态上来判断是 ...