cf 305 C(模拟)
2016-07-12 18:16
211 查看
链接: http://codeforces.com/problemset/problem/305/C
模拟下求解的过程,当ai == aj 时 两个合并为ai+1,最后模拟完可以发现 答案为 合并后的最大值-合并后的个数+1...具体看代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
set<ll>s;
int main()
{
ll n,a;
scanf("%lld",&n);
s.clear();
for(int i=0;i<n;i++)
{
scanf("%lld",&a);
while(!s.empty()&&s.find(a)!=s.end())
{
s.erase(s.find(a));
a++;
}
s.insert(a);
}
printf("%lld\n",(*s.rbegin()+1)-s.size());
return 0;
}
相关文章推荐
- 线程死锁
- 模拟售票
- 线程之间的通信
- 线程同步引发的安全问题
- UVA - 10250 The Other Two Trees
- sql server 与 mysql在自定以数据类型的区别
- java整型byte,short,int,long取值范围大小
- JAVA: List用法
- Java中List和ArrayList的区别
- JAVA的基本数据类型和引用数据类型的区别
- UVA - 10879 Code Refactoring
- JQuery Easy Ui dataGrid 数据表格
- C语言实现二叉树
- 经验
- UVA - 10010 Where's Waldorf?
- 关于变量和函数的初始化和执行次序
- eclipse去掉对js的Validation
- tomcat 日志log4j,slf4j,logback冲突
- 利用ucenter整合discuz数据
- Android TextView文字中底部或者中间加横线