As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine whatmaximum number of snowmen they can make from those snowballs.
The first line contains integer n (1 ≤ n ≤ 105) — the number of snowballs. The next line contains n integers — the balls' radii r1, r2, ...,rn (1 ≤ ri ≤ 109). The balls' radii can coincide.
Print on the first line a single number k — the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers — the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.
7
1 2 3 4 5 6 7
2
3 2 1
6 5 4
3
2 2 3
0
14 1 1 2 2 3 3 4 4 4 4 5 5 5 5


1 #include <bits/stdc++.h> 2 using namespace std; 3 4 struct Node{ 5 int arr,num; //半径,数目 6 }node[100005]; 7 map <int,int> M; 8 priority_queue <Node> Q; //默认大根队列,先出队列的为最大的 9 vector <int> V[3]; 10 11 bool operator < (Node a,Node b){ 12 return a.num < b.num; 13 } 14 int main() 15 { 16 ios_base::sync_with_stdio(0); 17 cin.tie(0); 18 19 int n; 20 while(cin>>n){ 21 while(!Q.empty()) 22 Q.pop(); 23 M.clear(); 24 for(int i = 0;i < 3;i ++) V[i].clear(); 25 26 int temp; 27 for(int i = 1;i <= n;i ++){ 28 cin>>temp; 29 M[temp]++; 30 } 31 32 int len = 0; 33 map <int,int>::iterator it; 34 for(it = M.begin();it != M.end();it ++){ //结构体存半径和数目 35 node[len].arr = it->first; 36 node[len++].num = it->second; 37 } 38 for(int i = 0;i < len;i ++) //入队列 39 Q.push(node[i]); 40 41 //cout<<"Check 2"<<endl; 42 len = 0; 43 while(!Q.empty()){ 44 Node res1 = Q.top(); 45 Q.pop(); 46 if(Q.empty()) break; 47 Node res2 = Q.top(); 48 Q.pop(); 49 if(Q.empty()) break; 50 Node res3 = Q.top(); 51 Q.pop(); 52 53 //cout<<res1.num<<" "<<res2.num<<" "<<res3.num<<endl; 54 55 int temp[3] = {res1.arr,res2.arr,res3.arr}; 56 sort(temp,temp+3); 57 V[0].push_back(temp[2]); 58 V[1].push_back(temp[1]); 59 V[2].push_back(temp[0]); 60 61 res1.num--,res2.num--,res3.num--; 62 if(res1.num) Q.push(res1); //数目不为0时继续入队列 63 if(res2.num) Q.push(res2); 64 if(res3.num) Q.push(res3); 65 } 66 cout<<V[0].size()<<endl; 67 for(int i = 0;i < V[0].size();i ++) 68 cout<<V[0][i]<<" "<<V[1][i]<<" "<<V[2][i]<<endl; 69 } 70 return 0; 71 }