您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: