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

【题意】

题意

【题解】

每次都选择剩余个数最多的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. [Swift通天遁地]一、超级工具-(6)通过JavaScript(脚本)代码调用设备的源生程序

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. MySQL索引使用以及优化

    优化后台业主评价服务人员运行缓慢.   案发现场:后台业主评价服务人员列表页以及搜索页运行缓慢.运行时间为24074ms.   排查过程: 1.代码开头加时间,结束加时间.看运行了多少秒. 2.给评价 ...

  3. eclipse mybatis 快速生成工具

    1.首先,得先看看eclipse有没安装mybatis generator插件,如果有的话,请忽略这一步 eclipse在线安装mybatis generator 1.打开eclipse,找到help ...

  4. 生成 Guid

    //生成Guid    function getGuidGenerator() {        var S4 = function () {            return (((1 + Mat ...

  5. [转]C语言文件操作函数大全(超详细)

    fopen(打开文件)相关函数 open,fclose表头文件 #include<stdio.h>定义函数 FILE * fopen(const char * path,const cha ...

  6. lua调用java java调用lua[转载]

    转载:http://dualface.github.io/blog/2013/01/01/call-java-from-lua/LuaJavaBridge - Lua 与 Java 互操作的简单解决方 ...

  7. 向listview控件中添加数据库数据

    //连接字符串 string str = "Data Source=.;Initial Catalog=mu;User ID=sa;Password=111"; //创建数据库连接 ...

  8. 6.12---select

  9. 利用反射重写toString()方法

    为了方便输出对象,Object类提供了toString()方法.但是该方法的默认值是由类名和哈希码组成的,实用性并不强.通常需要重写该方法以提供更多的信息.本实例使用反射输出类的包.类的名字.类的公共 ...

  10. 通过重写.htaccess文件添加404

    如果说是用linux服务器的系统 想要给自己的网站设置404怎么弄?如果你不会给自己的Ecs服务器添加服务器管理系统,或是你购买的云虚拟主机没有304.404设置,那么就要通过自己重写文件来设置404 ...