【Codeforces 140C】New Year Snowmen
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
每次都选择剩余个数最多的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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- bzoj 2200: [Usaco2011 Jan]道路和航线【spfa】
直接跑最短路就行了--还不用判负环 #include<iostream> #include<cstdio> #include<queue> using namesp ...
- NetCore Netty 框架 BT.Netty.RPC 系列随讲 —(前序) REST API 与 RPC 经典网络基础服务架构
在服务体系架构内,我们所知道的,有两种请求模型: Http 请求模型,以及 RPC 请求模型.因此,在一个互联网请求模型架构上,都是这两种的请求模型的向互组合. 下面给出两种常见的互联网经典基础架构图 ...
- JavaScript--DOM删除节点removeChild()
删除节点removeChild() removeChild() 方法从子节点列表中删除某个节点.如删除成功,此方法可返回被删除的节点,如失败,则返回 NULL. 语法: nodeObject.remo ...
- PROTEUS快捷键与部分知识点
缩放 有以下几种方法对原理图进行缩放: 移动鼠标需要所放的地方,滚动鼠标滑轮进行缩放. 移动师表需要缩放的地方,按键盘F6放大,F7缩小 按下ShIFT键,鼠标左键拖拽出需要放大的区域,这叫SHIFT ...
- 最大化最小值poj2456Aggressive cows
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15528 Accepted: 7440 ...
- 类函数:string、math
类:系统内置的处理字符串类型的函数方法类. string是String的快捷方式.所包含的内容都是一样的. Int i=x.length;//获取一个字符串长度 字符串中,索引号从0开始 String ...
- datagrid上面的查询按钮设置了,但是分页工具栏不显示
原因:查询的linkbutton没有放在toolbar里. <script type="text/javascript"> $(function(){ $('#dg') ...
- div常用效果方法-transform
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- solr深分页,游标操作分页,解决性能问题
solr深分页,游标操作分页,解决性能问题 @Test public void pageByCursor() { try { solrServer.connect(); String query = ...
- TortoiseSVN客户端不能记住用户名和密码
TortoiseSVN客户端重新设置用户名和密码 在第一次使用TortoiseSVN从服务器CheckOut的时候,会要求输入用户名和密码,这时输入框下面有个选项是保存认证信息,如果选了这个选项,那么 ...