【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

每次都选择剩余个数最多的3个不同数字组成一组.
优先消耗剩余个数多的数字
这样能尽量让剩余的数字总数比较多,从而更加可能得到更多的3个组合

【代码】

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5; int n;
map<int,int> dic;
priority_queue<pair<int,int>,vector<pair<int,int> >,less<pair<int,int> > > pq;
vector<pair<int,pair<int,int> > > ans; int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++) {
int x;
cin >> x;
dic[x]++;
}
for (pair<int,int> temp:dic){
pq.push(make_pair(temp.second,temp.first));
}
while ((int)pq.size()>=3){
pair<int,int> temp1 = pq.top();pq.pop();
pair<int,int> temp2 = pq.top();pq.pop();
pair<int,int> temp3 = pq.top();pq.pop();
if (temp1.second<temp2.second) swap(temp1,temp2);
if (temp1.second<temp3.second) swap(temp1,temp3);
if (temp2.second<temp3.second) swap(temp2,temp3);
ans.push_back(make_pair(temp1.second,make_pair(temp2.second,temp3.second)));
temp1.first--;
if (temp1.first>0) pq.push(temp1);
temp2.first--;
if (temp2.first>0) pq.push(temp2);
temp3.first--;
if (temp3.first>0) pq.push(temp3);
}
cout<<(int)ans.size()<<endl;
for (int i = 0;i < (int)ans.size();i++){
cout<<ans[i].first<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<endl;
}
return 0;
}

【Codeforces 140C】New Year Snowmen的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. 栗染-git命令搭建简单的个人的网页

    本来一个很简单的东西被自己搞了很久 可能是对于一个小白来说第一次认识到github的魅力吧,以前只是听别人说过用github搭建网站,听起来很厉害的样子,一直也没有尝试过,突然兴起今天去网上找一些教程 ...

  2. codeforces GYM 100781A【树的直径】

    先求出每棵树的直径,排个序,要想图的直径最小的话需要每棵树的直径中点像直径最大的树的直径中点连边,这样直径有三种情况:是直径最大的树的直径:a[tot]:是直径最大的树和直径第二大的树的半径拼起来+1 ...

  3. activiti遇到的问题

    1.act_hi_detail表里面没有数据 原因是没有加历史变量的判断 2.流程图添加网关,写流转表达式 比如请假流程   大于3天小于5天的条件:${请假实体类.属性名称}

  4. Linux环境下安装JDK并配置环境变量

    首先查看是否已经安装了JDK并配置环境变量. [root@dhcc_plat opt]# java -version -bash: java: command not found [root@dhcc ...

  5. js调试技巧汇总中

    由于设备多样性(PC.ios.安卓.pad.tv)以及各设备对js脚本支持性差异性.js兼容性调试显得越来越重要. 0:尽力模仿真实场景下进行调试,迅速定位问题以及提供解决方案. 1:setTimeo ...

  6. myeclipse中js文件报错

    这几天在myeclipse中添加文件时,会报错,但是代码是从官网上下载的,没有错误,只是myeclipse的检查较为严格.在网上找到解决方案,希望可以帮到强迫症的人. 解决步骤: 1.window→P ...

  7. JAVA使用Ldap操作AD域

    项目上遇到的需要在集成 操作域用户的信息的功能,第一次接触ad域,因为不了解而且网上其他介绍不明确,比较费时,这里记录下. 说明: (1). 特别注意:Java操作查询域用户信息获取到的数据和域管理员 ...

  8. [ Nowcoder Contest 167 #C ] 部分和

    \(\\\) \(Description\) 给出一个长度为\(N\)的数组\(A[i]\),保证\(N\)为 \(2\) 的整次幂. 对于每个 \(i\ (i\in [0,N))\)求所有满足\(( ...

  9. Android Programming 3D Graphics with OpenGL ES (Including Nehe's Port)

    https://www3.ntu.edu.sg/home/ehchua/programming/android/Android_3D.html

  10. daxcie

    Database->Edit Current DBMS菜单 修改如下:选中General选项卡,依次打开Script->Sql->Fomat->CaseSensitivityU ...