CF140C

题目大意:堆雪人,需要三个大小不同的雪球,现有\(n\)个给定大小的雪球,问最多堆多少个雪人

一个很明显的思路是把每种雪球出现的个数记录下来,然后直接扔到大根堆里面,每次选择剩下出现次数最多的三个堆成一个雪人,可以证明,这样一定不会比选择小的更劣

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 3;
int a[N];
int n;
int s[5];
priority_queue <pii> q;
struct node{
int x,y,z;
}qq[N];
inline int read(){
int v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
int main(){
n = read();
for(int i = 1;i <= n;++i) a[i] = read();
sort(a + 1,a + n + 1);
int res = 1;
for(int i = 1;i <= n;++i){
if(a[i] == a[i + 1]) res++;
else{
q.push(mk(res,a[i]));
res = 1;
}
}int ans = 0;
while(q.size() >= 3){
pii k1 = q.top();q.pop();
pii k2 = q.top();q.pop();
pii k3 = q.top();q.pop();
ans++;
s[1] = k1.se,s[2] = k2.se,s[3] = k3.se;
sort(s + 1,s + 4);
qq[ans] = (node){s[3],s[2],s[1]};
k1.fi--,k2.fi--,k3.fi--;
if(k1.fi) q.push(k1);
if(k2.fi) q.push(k2);
if(k3.fi) q.push(k3);
}
printf("%d\n",ans);
for(int i = 1;i <= ans;++i) printf("%d %d %d\n",qq[i].x,qq[i].y,qq[i].z);
return 0;
}

最新文章

  1. C文件读写
  2. Servlet3.0 jsp跳转到Servlet 出现404错误的路径设置方法
  3. Jexus针对Asp.net core应用程序的六大不可替代的优势
  4. 基于Task的异步模式--全面介绍
  5. Angular 2 要来了,Wijmo 已准备好迎接
  6. Android Animation学习(二) ApiDemos解析:基本Animators使用
  7. Java 读取excel 文件 Unable to recognize OLE stream 错误
  8. HDU 2579 (记忆化BFS搜索)
  9. OmniThreadLibrary 3.03b发布了
  10. 在yii中使用gearman
  11. PS流格式
  12. 基于ACE的定时器模板类
  13. GET和POST本质上有什么区别
  14. php xcache 配置 使用 (转载)
  15. discuz 万能SQL查询调用语句写法
  16. spring aop + xmemcached 配置service层缓存策略
  17. 谈谈PCI的GXL
  18. Erlang Rebar 使用指南之四:依赖管理
  19. 使用 coverlet 查看.NET Core应用的测试覆盖率
  20. Docker Compose 原理

热门文章

  1. fedora 安装ftp
  2. 封装好的MySQL.class.php类
  3. 使用R拟合分布
  4. 【JZOJ4359】【GDKOI2016】魔卡少女
  5. poj2391 最大流+拆点
  6. hdu1532&amp;&amp;poj1273 最大流
  7. hdu1848 sg打表
  8. 纯CSS3打造圆形菜单
  9. 括号序列问题 uva 1626 poj 1141【区间dp】
  10. 2019-8-31-dotnet-使用-lz4net-压缩-Stream-或文件