您的位置:首页 > 其它

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