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

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

题目链接:http://codeforces.com/contest/722/problem/D

1
#include <bits/stdc++.h> 2 #include <iostream> 3 #include <queue> 4 #include <stdio.h> 5 #include <string.h> 6 #include <algorithm> 7 #include <string> 8 #include <math.h> 9 #include <set>10 #include <map>11 #define mod 100000000712 #define MAXN 100+1013 #define INF 100000000014 #define eps 10e-615 #define ll long long16 using namespace std;17 18 bool cmp(int a, int b)19 {20 return a > b;21 }22 23 //******************************************************************************24 25 int main(void)26 {27 //std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);28 int n;29 set<int>st;30 cin >> n;31 for(int i=0; i<n; i++)32 {33 int x;34 cin >> x;35 st.insert(x);36 }37 while(1)38 {39 int x=*st.rbegin(), i;40 for(i=x; i&&st.count(i); i/=2); //***st.count(x)查找st里i出现的次数41 if(!i)42 {43 break;44 }45 st.erase(x);46 st.insert(i);47 }48 for(int it : st) //***类似java里面的加强for循环49 {50 printf("%d ", it);51 }52 printf("\n");53 return 0;54 }

 

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