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 r1r2, ..., rn. 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 r1r2, ..., rn (1 ≤ ri ≤ 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.

Examples

Input
7
1 2 3 4 5 6 7
Output
2
3 2 1
6 5 4
Input
3
2 2 3
Output
0

思路:贪心,每次选出还剩的最大的三个组成一个雪人,用优先队列为数据结构,代码如下:
struct Node {
int id, sum;
Node(int _id = , int _sum = ) : id(_id), sum(_sum){}
bool operator<(const Node &a) const {
return sum < a.sum;
}
}; struct Snowman {
int a, b, c;
Snowman(int _a, int _b, int _c) : a(_a), b(_b), c(_c){}
}; bool comp(int a,int b) {
return a > b;
}
map<int, int> Cache;
vector<Snowman> res;
int n; int main() {
scanf("%d", &n);
priority_queue<Node> q;
for (int i = ; i < n; ++i) {
int tmp;
scanf("%d", &tmp);
Cache[tmp]++;
}
for(auto i = Cache.begin(); i != Cache.end(); ++i)
q.push(Node(i->first,i->second));
while(q.size() > ) {
Node t1, t2, t3;
t1 = q.top(), q.pop();
t2 = q.top(), q.pop();
t3 = q.top(), q.pop();
res.push_back(Snowman(t1.id, t2.id, t3.id));
t1.sum--, t2.sum--, t3.sum--;
if(t1.sum > ) q.push(t1);
if(t2.sum > ) q.push(t2);
if(t3.sum > ) q.push(t3);
}
printf("%d\n", res.size());
for (int i = ; i < res.size(); ++i) {
int tmp[];
tmp[] = res[i].a, tmp[] = res[i].b, tmp[] = res[i].c;
sort(tmp, tmp + , comp);
for(int j = ; j < ; ++j) {
if(j)
printf(" ");
printf("%d", tmp[j]);
}
printf("\n");
}
return ;
}
 

Day3-E-New Year Snowmen CodeForces140C的更多相关文章

  1. 冲刺阶段day3

    day3 项目进展 今天周三,我们五个人难得的一整个下午都能聚在一起.首先我们对昨天的成果一一地查看了一遍,并且坐出了修改.后面的时间则是做出 登录界面的窗体,完善了登录界面的代码,并且实现了其与数据 ...

  2. python笔记 - day3

    python笔记 - day3 参考:http://www.cnblogs.com/wupeiqi/articles/5453708.html set特性: 1.无序 2.不重复 3.可嵌套 函数: ...

  3. python_way,day3 集合、函数、三元运算、lambda、python的内置函数、字符转换、文件处理

    python_way,day3 一.集合 二.函数 三.三元运算 四.lambda 五.python的内置函数 六.字符转换 七.文件处理 一.集合: 1.集合的特性: 特性:无序,不重复的序列 如果 ...

  4. Spark菜鸟学习营Day3 RDD编程进阶

    Spark菜鸟学习营Day3 RDD编程进阶 RDD代码简化 对于昨天练习的代码,我们可以从几个方面来简化: 使用fluent风格写法,可以减少对于中间变量的定义. 使用lambda表示式来替换对象写 ...

  5. Spark Tungsten揭秘 Day3 内存分配和管理内幕

    Spark Tungsten揭秘 Day3 内存分配和管理内幕 恭喜Spark2.0发布,今天会看一下2.0的源码. 今天会讲下Tungsten内存分配和管理的内幕.Tungsten想要工作,要有数据 ...

  6. Catalyst揭秘 Day3 sqlParser解析

    Catalyst揭秘 Day3 sqlParser解析 今天我们会进入catalyst引擎的第一个模块sqlparser,它是catalyst的前置模块. 树形结构 从昨天的介绍我们可以看到sqlPa ...

  7. Kakfa揭秘 Day3 Kafka源码概述

    Kakfa揭秘 Day3 Kafka源码概述 今天开始进入Kafka的源码,本次学习基于最新的0.10.0版本进行.由于之前在学习Spark过程中积累了很多的经验和思想,这些在kafka上是通用的. ...

  8. python s12 day3

    python s12 day3   深浅拷贝 对于 数字 和 字符串 而言,赋值.浅拷贝和深拷贝无意义,因为其永远指向同一个内存地址. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  9. Day3 - Python基础3 函数、递归、内置函数

    Python之路,Day3 - Python基础3   本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8. ...

随机推荐

  1. python opencv:保存图像

  2. vs的一些操作技巧:在写代码时自动换行的设置

    有时在写代码的时候,一行代码太长了,想换行,直接按回车键的话又会报错,怎么办?其实可以这样设置vs,就可以达到自动换行的效果啦. ​

  3. 服务器(1)——IIS(1)——Windows7中IIS简单安装与配置(详细图解)

    最近工作需要IIS,自己的电脑又是Windows7系统,找了下安装的方法,已经安装成功. 一.首先是安装IIS.打开控制面板,找到“程序与功能”,点进去 二.点击左侧“打开或关闭Windows功能” ...

  4. SpringBoot与Mybatis整合(包含generate自动生成代码工具,数据库表一对一,一对多,关联关系中间表的查询)

    链接:https://blog.csdn.net/YonJarLuo/article/details/81187239 自动生成工具只是生成很单纯的表,复杂的一对多,多对多的情况则是在建表的时候就建立 ...

  5. wx小程序笔记

    目录 p18 事件绑定1 p19 事件绑定2 btn p20+ view 相关,wxss,less,css 零基础玩转微信小程序[黑马程序员] https://www.bilibili.com/vid ...

  6. 「CTSC2008」网络管理

    「CTSC2008」网络管理 传送门 整体二分做法,应该和这题一样的吧. 就是把序列换成树,第 \(k\) 小换成第 \(k\) 大. 然后就切了... 参考代码: #include <algo ...

  7. lnmp1.5安装memcache

    1.安装libevent 由于Memcache用到了libevent这个库用于Socket的处理,所以需要安装libevent. # wget http://www.monkey.org/~provo ...

  8. MinGW x64 for Windows安装

    1. 百度搜索MinGW gcc 或直接登录 MinGW gcc官网 http://www.mingw.org/ 2.选择左侧download链接,进入下载页面 3.下载安装包mingw-get-se ...

  9. iOS项目开发日常之创建文件(协议、类、分类、扩展)

    iOS项目开发过程中,是以不断创建文件的形式进行着的. 创建得比较频繁的文件类型是: 这两个类型中创建的文件有:子类.分类.扩展.协议四种文件,如下:    这四类文件是频繁创建的,我们来看一下各自分 ...

  10. POJ 2104 主席树模板题

    #include <iostream> #include <cstdio> #include <algorithm> int const maxn = 200010 ...