您的位置:首页 > 其它

Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)

2016-10-02 22:58 232 查看
题目链接:http://codeforces.com/contest/722/problem/D

1 #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <set>
#include <map>
#define mod  1000000007
#define MAXN 100+10
#define INF 1000000000
#define eps 10e-6
#define ll long long
using namespace std;

bool cmp(int a, int b)
{
return a > b;
}

//******************************************************************************

int main(void)
{
//std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
set<int>st;
cin >> n;
for(int i=0; i<n; i++)
{
int x;
cin >> x;
st.insert(x);
}
while(1)
{
int x=*st.rbegin(), i;
for(i=x; i&&st.count(i); i/=2);  //***st.count(x)查找st里i出现的次数
if(!i)
{
break;
}
st.erase(x);
st.insert(i);
}
for(int it : st)  //***类似java里面的加强for循环
{
printf("%d ", it);
}
printf("\n");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐