题目链接:https://cn.vjudge.net/contest/272792#problem/E

E - New Year Snowmen

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 r1, r2, ..., 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 r1, r2, ..., 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

思路:

贪心+优先队列,先把所有的r和num打包装进node结点,然后按照num的大小进队,出队三个元素,num--,不断地进队出队。都是num大的先出队,记个ok记录总个数。

知识点:

priority_queue<node> qq;使用默认优先队列 ,按照j降序 ,需要重载运算符< , 详解:https://blog.csdn.net/c20182030/article/details/70757660

sort(a,b)//排序函数 

int cmp ()
return a>b;//按照降序,(a<b)按照升序。 如果不定义cmp,默认从小到大,升序

运算符重载

bool operator <(  node b)  const
    {    
        
              return num<b.num;  ///重载为 数量大优先
    }

这个重载可以按照结点的数量排序,降序

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;
int ans[100000+5][3];
int vis[100000+5];
struct node
{int num,x;bool operator <(  node b)  const{    return num<b.num;  ///重载为 数量大优先 降序}
};
priority_queue<node> qq;//使用默认优先级比较符号<
int cmp(int a ,int b)
{return a>b;         //降序
}
int cmp2(node a ,node b)
{return a.x>b.x;         //降序
}int main()
{int n;cin>>n;int t;int i;for (i=1;i<=n;i++){scanf("%d",&t);vis[i]=t;}sort(vis+1,vis+1+n,cmp);for(i=1;i<=n;i++){int cun=1;while(vis[i]==vis[i+1]&&i<=n){cun++;i++;}   node t;t.num=cun;//t.x=vis[i];qq.push(t);//得到重复的个数及该数值 进入优先队列 }int ok=0;while(qq.size()>=3)     //不同的雪球种类>=3{node q[4];q[1].x=q[2].x=q[3].x=0;      q[1]=qq.top(),qq.pop(); //取出前三大,复杂度lognq[2]=qq.top(),qq.pop(); q[3]=qq.top(),qq.pop();
sort(q+1,1+q+3,cmp2);            //把雪球的半径排序,升序ans[++ok][0]=q[1].x; //记录答案ans[ok][1]=q[2].x;ans[ok][2]=q[3].x;q[1].num--;q[2].num--;q[3].num--;    //数量减一if(q[1].num)                 //若个数为零,丢弃,否则继续进入队列qq.push(q[1]);if (q[2].num)qq.push(q[2]);if (q[3].num)qq.push(q[3]);}printf("%d\n",ok);for (i=1;i<=ok;i++){printf("%d %d %d\n",ans[i][0],ans[i][1],ans[i][2]);}return 0;
}

注:个别代码选自网络,侵权请私信联系删除。

本人初学者,欢迎大家一起敲代码呀 呀咿呀咿呀~~~~~~~~

E - New Year Snowmen相关推荐

  1. New Year Snowmen codeforces 140C

    题目 As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowme ...

  2. L - New Year Snowmen

    As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. ...

  3. 贪心(优先队列) - New Year Snowmen - CodeForces - 140C

    贪心(优先队列) - New Year Snowmen - CodeForces - 140C 题意: 给定一个长度为n的正整数序列a1,a2,...,an.给定一个长度为n的正整数序列a_1,a_2 ...

  4. New Year Snowmen(贪心)

    As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. ...

  5. New Year Snowmen((贪心)map+优先队列)

    文章目录 一.题目 二.解题步骤 1.题意 2.思路 Source Program 一.题目 New Year Snowmen:传送门 Examples Input 7 1 2 3 4 5 6 7 O ...

  6. CodeForces - 140C New Year Snowmen

    CodeForces - 140C New Year Snowmen 题意: 现在来做雪人,每个雪人由三个不同大小的雪球构成:一个大的,一个中等的,一个小的.现在有 n 个雪球半径分别为 r1, r2 ...

  7. CF140C-New Year Snowmen【优先队列】

    正题 题目链接:https://www.luogu.com.cn/problem/CF140C 题目大意 nnn个雪球,一个雪人需要用333个不同大小的雪球堆起,求最多雪人. 解题思路 我们每次拿相同 ...

  8. Winter And Snowmen

    https://vjudge.net/problem/TopCoder-12891 暴力想法是:dp[i][s1][s2]前i个,第一个集合xor是s1,第二个集合xor是s2方案数O(n^3) 有x ...

  9. Codeforces140CNew Year Snowmen

    一道优先队列好题 不难发现,每次取最多的几个雪球能保证凑出来的雪人最多,然后我们就先离散化一下,然后封装丢到优先队列里,每次取出队首的三个,将数量各自减一 ,表示凑了一个雪人,然后将数量大于一的再丢回 ...

最新文章

  1. 布尔定理及证明(完整版)
  2. 日本面向未来的特定科技领域技术预见分析
  3. PCB设计用什么软件好?
  4. SAP用户信息查询的几张表
  5. 三维叉乘怎么算_3分钟做完这些题,你的CAD才算熟练
  6. 单向链表的建立和简单的增删改查
  7. java log4j 代码配置文件_除了Log4jXML、属性文件和源代码(主要是Java)之外的配置日志的方法?...
  8. 在项目中使用redis的原因
  9. 中国速度袋行业市场供需与战略研究报告
  10. 第七届 蓝桥杯 省赛 第七题 剪邮票
  11. erlang的运算符
  12. LCM模组的简介与质量管理(连载四)
  13. 产品经理从专能到全能——不再虚无缥缈的用户体验
  14. Java实现二维码制作
  15. 用计算机表白我不喜欢你了,“我喜欢你”用文言文怎么说?拿这3句去表白,男生不忍心拒绝你!...
  16. 最新 2022 年云原生Kubernetes 高级面试题大全(持续更新中)
  17. python_pdf常规使用
  18. 4天接待180万游客!里昂灯光节的这些作品你都看懂了吗?
  19. 使用普通打印机打印条码标签
  20. border-radius 构建规则讲解 及 50% 和 100% 的异同

热门文章

  1. GIT无法提交到码云。原因可能是所在提交位置不对
  2. 考研英语 词根词缀单词71-80
  3. LeCo-3. 无重复字符的最长子串
  4. 如果GOOGLE退出中国,我们怎么办???
  5. WES分析2-分析流程
  6. 飞凌单片机解密_GX28E01单片机解密
  7. android launcher启动过程,Android应用启动过程-Launcher源码浅析
  8. 搜索引擎的网址收录链接
  9. UI设计培训分享:UI设计的职业发展路径
  10. 模型包装,答辩吹牛方法论!