As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey’s twins help him: they’ve already made n snowballs with radii equal to r 1, r 2, …, r n. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs.

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of snowballs. The next line contains n integers — the balls’ radii r 1, r 2, …, r n (1 ≤ r i ≤ 109). The balls’ radii can coincide.

Output
Print on the first line a single number k — the maximum number of the snowmen. Next k lines should contain the snowmen’s descriptions. The description of each snowman should consist of three space-separated numbers — the big ball’s radius, the medium ball’s radius and the small ball’s radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.

这一题除了注意元素的大小循序,还要按照重复元素多少进行排序,这样才能保证雪人数量最大。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define fors( x, y,z) for(int x=y;x<=z;x++)
#define test printf("<><><><><>\n");
int n;
int arr[1000001];
map<int,int>store;
struct cmp{bool operator()(int x,int y)const {if(store[x]==store[y])return x<y;
else return store[x]<store[y];}
};
priority_queue<int,vector<int>,cmp>bag;
void init()
{int ttol;scanf("%d",&n);fors(i,1,n){scanf("%d",&ttol);store[ttol]++;}
}
void solve()
{int v=0;map<int,int>::iterator it=store.begin();for(it;it!=store.end();it++)bag.push(it->first);while(bag.size()>=3){int x=bag.top();store[x]--;bag.pop();int y=bag.top();bag.pop();store[y]--;int z=bag.top();bag.pop();store[z]--;int vl=arr[0]*3;if(x<y) swap(x,y);if(x<z) swap(x,z);if(y<z) swap(y,z);arr[vl+1]=x;arr[vl+2]=y;arr[vl+3]=z;arr[0]++;if(store[x])bag.push(x);if(store[y])bag.push(y);if(store[z])bag.push(z);}printf("%d\n",arr[0]);fors(i,0,arr[0]-1)printf("%d %d %d\n",arr[i*3+1],arr[i*3+2],arr[i*3+3]);
}
int main()
{init();solve();
}

L - New Year Snowmen相关推荐

  1. GCC 连接器、链接标准库 gcc -l、链接手动创建库(指定目录的库 gcc -L)

    1. 链接器 链接器把多个二进制的目标文件(object file)链接成一个单独的可执行文件. 在链接过程中,它必须把符号(变量名.函数名等一些列标识符)用对应的数据的内存地址(变量地址.函数地址等 ...

  2. Uva 3767 Dynamic len(set(a[L:R])) 树套树

    Dynamic len(set(a[L:R])) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://uva.onlinejudge.org/in ...

  3. l开头的英文车标是什么车_汽车品牌车标大全,有哪些品牌的车标你没见过?...

    汽车产业已经发展100多年了,那全世界一共出现了多少汽车品牌有人知道吗,这个数字基本靠猜:因为很多品牌没生存几年就消失在世界上了,留下来的汽车品牌少之又少. 今天跟大家分享一些比较熟知的汽车品牌标志, ...

  4. 这就是我为什么推荐使用var aa = for (var i = 0, l = aa.length; i < l; i++) {var a = aa[i];}循环的原因,每秒最快可以执行4000+次!

    //很长一段时间我都只使用以下方式做数组循环,具体原因看数据 var aa = for (var i = 0, l = aa.length; i < l; i++) { var a = aa[i ...

  5. 设置VSCode终端命令行清除快捷键Ctrl+K或Ctrl+L

    Ctrl+K Ctrl+S设置 终端:清除Ctrl+K 也可以 输入terminal.clear设置Ctrl+L(建议设置这个,避免和其他Ctrl+K组合键冲突) 接下来去验证下吧 Ctrl+J打开终 ...

  6. [kuangbin带你飞]专题六 最小生成树 L - 还是畅通工程 (简单最小生成树)

    L - 还是畅通工程 题目链接:https://vjudge.net/contest/66965#problem/L 题目: 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府&qu ...

  7. 2016多校赛2 A 数学推公式 E 极角排序,组合数(待补) L dp+bitset优化

    2016 Multi-University Training Contest 2 A - Acperience 题意:给出w[],求S((w[i]-aB[i])^2)的最小值(B[i]为1或-1). ...

  8. ls -l |wc -l命令多统计一行

    #ls -l |wc -l 注意:总用量也占用1行,所以统计出来的是14而不是13 其他网友提醒 #ls -l |wc -l 就统计实际的行,放大就看出效果 1和l不同

  9. 【C】printf warning: unknown conversion type character ‘l‘ in format [-Wformat=]

    1.问题描述 在使用printf.fprintf打印long long类型时报错 printf warning: unknown conversion type character 'l' in fo ...

最新文章

  1. Part2_2 Bs4常见操作
  2. LiveVideoStackCon 2020 漫游指南
  3. hibernate 排序_Hibernate提示:排序和排序
  4. php sub pos,PHP pos() 函数
  5. php7 mcrypt模块_Linux下PHP安装mcrypt扩展模块笔记
  6. Linux 权限设置
  7. php 删除最后一个空数组,php删除空数组
  8. Eclipse,提交代码,版本比较时,不忽略空格
  9. qml 函数使用经验总结1(image中调用函数)
  10. ASP.NET版本不是1.1, 2.0的也一样
  11. C中使用汇编交换两个值
  12. jQuery 文档碎片处理
  13. Windows系统-删除指定服务!
  14. cad导入进max线会乱_AutoCAD导入3dmax显示错乱(z轴归零).doc
  15. JAVA查询银行卡信息
  16. PS 2019 Mac版 自学入门系列(九)—— 复制小对象和纹理
  17. Web 压测工具介绍
  18. Web Audio API之手把手教你用web api处理声音信号:可视化音乐demo
  19. 【博客635】tcpdump原理与网卡混杂模式
  20. 海格里斯大型双层冷库建设 蔬菜水果农产品multi-storey cold store

热门文章

  1. tp5系统常量对应的目录路径
  2. 什么是MTTF,MTBF?
  3. Wangle源码分析:Service
  4. 四、redi性能测试、协议、事务
  5. Civil3D 2018-03 曲面创建
  6. win激活时错误0xc0000022
  7. stm32h7能跑linux,STM32H7榨干了Cortex-M7的最后一滴血
  8. Mounty 1.10免费版(NTFS硬盘工具)支持big sur
  9. 刚刚涉足神经网络,基于TensorFlow2.0以实现鸢尾花分类为例总结神经网络代码实现的几个步骤,附代码详细讲解
  10. 二、C++反作弊对抗实战 (进阶篇 —— 4.遍历进程模块(暴力扫描整个内存找出被断链的))