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

【题意】

题意

【题解】

每次都选择剩余个数最多的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. matlab进入指定目录

    cd C:\Users\hui\Desktop\minepy\1\minepy-1.2.0\minepy-1.2.0\matlab

  2. java运行jdk连接mysql出现了:Establishing SSL connection without server's identity verification is not recommended

    注意:出现这类提示也不会影响对数据库的增删改查操作,所以不用紧张.. 在运行练习时出现下面的错误信息提示: Establishing SSL connection without server's i ...

  3. [读书笔记1]《C语言嵌入式系统编程修炼》

      大学前两年一直搞的是单片机,写的是嵌入式C语言程序,走过了不少弯路,现在感觉仍然在走弯路.有幸偶尔看到了这篇文章,深感自己以前写程序的时候存在很多误区.现写篇博客做下总结. 作者:宋宝华出处:天极 ...

  4. C#方法的一些规则

    C# 方法 一个方法是把一些相关的语句组织在一起,用来执行一个任务的语句块.每一个 C# 程序至少有一个带有 Main 方法的类. 要使用一个方法,您需要: 定义方法 调用方法 下面是方法的各个元素: ...

  5. 【雅虎2017】一个在线展示广告的CVR预估框架实践

    论文A Practical Framework of Conversion Rate Prediction for Online Display Advertising 定期更新,获取更多,欢迎sta ...

  6. 解决Unicode编码(&#29848;)

    随着互联网发展,B/S越来越受欢迎 Code编码格式也越来载多, 在大千花花世界 中文在Web显示看似一样但实际编码并不样,导致从页面获取的资料录入到数据库中时 存取的就是Code编码 如:Unico ...

  7. plc学习笔记

    防抖编程代码备份 如果定时到了还未检测到下降沿,则认为信号有效.这一端程序主要是针对现场装料杯在输送过程中由于传送带原因,电眼时常产生无效停机信号,需要过滤,因此需要在电眼检测中添加防抖功能 2018 ...

  8. 业余开发Android App的架构演变

    闲暇之余,开发了一款休闲类app,虽然用户量不多,但确实花了不少心血在这上面.然而,开发出来的结果,与之前想好的架构,还是有不少区别. 下面,记录下这款app架构的演变: 最初,只想写个app,能与机 ...

  9. typeloadexception 方法实现中引用的声明不能是final方法

    问题描述: 1. 修改了DVSNetClient项目,其依赖类库CameraDSP没有改动.CameraDSP_DVSNetClient.dll的版本编号和文件编号由1.0.0.0变为1.0.1.0. ...

  10. 【C++】智能指针简述(二):auto_ptr

    首先,我要声明auto_ptr是一个坑!auto_ptr是一个坑!auto_ptr是一个坑!重要的事情说三遍!!! 通过上文,我们知道智能指针通过对象管理指针,在构造对象时完成资源的分配及初始化,在析 ...