码迷,mamicode.com
首页 > 其他好文 > 详细

D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))

时间:2018-04-12 19:49:54      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:rom   i++   erase   system   for   namespace   equals   def   use   

模拟题,运用强大的stl。

 1 #include <iostream>
 2 #include <map>
 3 #include <algorithm>
 4 #include <set>
 5 
 6 #define N 150005
 7 using namespace std;
 8 typedef long long Int;
 9 const int maxn = 1e9 + 7;
10 map<long long, set<int> > mapp;
11 long long a[N];
12 
13 int main()
14 {
15     int n;
16     cin >> n;
17     int all = n;
18     for (int i = 1; i <= n; i++)
19     {
20         cin >> a[i];
21         mapp[a[i]].insert(i);
22     }
23     for (map<long long, set<int> >::iterator i = mapp.begin(); i != mapp.end(); i++)
24     {
25         while (i->second.size() > 1)
26         {
27             set<int>::iterator op1 = i->second.begin(), op2;
28             op2 = op1; op2++;
29             all--;
30             int t1 = *op1, t2 = *op2;
31             a[t1] = -1;
32             a[t2] *= 2;
33             mapp[a[t2]].insert(t2);
34             i->second.erase(op1);
35             i->second.erase(op2);
36         }
37     }
38     cout << all << endl;
39     for (int i = 1; i <= n; i++)
40     {
41         if (a[i] != -1)
42             cout << a[i] << " ";
43     }
44 
45     //system("pause");
46     return 0;
47 }

 

D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))

标签:rom   i++   erase   system   for   namespace   equals   def   use   

原文地址:https://www.cnblogs.com/jaydenouyang/p/8809916.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!