CodeForces 140C - New Year Snowmen STL
2016-09-06 14:22
288 查看
//http://codeforces.com/group/5pcxnzwAHv/contest/140/problem/C //set和map的应用 //set是只读的,不能直接对其中数据进行改写 #include <stdio.h> #include <string> #include <cstring> #include <queue> #include <algorithm> #include <functional> #include <vector> #include <iomanip> #include <math.h> #include <iostream> #include <sstream> #include <time.h> #include <stack> #include <set> #include <map> #include <time.h> #include <bitset> using namespace std; map<int,int> mp; set<pair<int,int> > st; vector<int> Ans; map<int,int>::iterator mpit; set<pair<int,int> >::iterator stit; int K; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int a; cin>>K; for (int i=0; i<K; i++) { cin>>a; mp[a]++; } for (mpit=mp.begin(); mpit!=mp.end(); mpit++) st.insert(make_pair(mpit->second,mpit->first)); while (st.size()>=3) { pair<int,int> cur[3]; for (int i=0;i<3;i++) { cur[i]=*--st.end(); st.erase(--st.end()); Ans.push_back(cur[i].second); } for (int i=0;i<3;i++) if (--cur[i].first) st.insert(cur[i]); sort(Ans.rbegin(),Ans.rbegin()+3); } cout<<Ans.size()/3<<endl; for (int i=0;i<(int)Ans.size();i++) cout<<Ans[i]<<((i+1)%3==0?'\n':' '); return 0; }
相关文章推荐
- CodeForces 140C - New Year Snowmen(数据结构)
- Codeforces 140C New Year Snowmen(贪心)
- CodeForces - 140C-New Year Snowmen
- CodeForces 140C - New Year Snowmen(优先队列)
- [CodeForces - 140C New Year Snowmen] 贪心 + STL 优先队列
- CodeForces - 140C New Year Snowmen(贪心)
- CodeForces 140C - New Year Snowmen
- New Year Snowmen CodeForces - 140C
- codeforces 140C New Year Snowmen
- New Year Snowmen CodeForces - 140C
- Codeforces Round #100//140C - New Year Snowmen C. New Year Snowmen
- CodeForces 140 C. New Year Snowmen 详解 (贪心+优先队列)
- CoderForce 140C-New Year Snowmen(贪心)
- CodeForces-379A-New Year Candles
- Codeforces 500A:New Year Transportation(水题)
- codeforces。 goodbye 2017。 B. New Year and Buggy Bot
- CodeForces 500A New Year Transportation
- Codeforces 500B - New Year Permutation (思维)
- CodeForces 500B Good Bye 2014 New Year Permutation
- Codeforces edu 6. E New Year Tree 图论 线段树