CodeForces 140C New Year Snowm
题目链接:http://codeforces.com/contest/140/problem/C
题目大意:
有n个雪球(半径为:r1,r2,r3.....rn);一个雪人要三个雪球。但是要求半径两两不相同。
求可以堆雪人数量的最大值。
输入
第一行n代表了雪球数量。
第二行,n个数字代表了雪球的半径。
输出
第一行 k 代表了可以堆几个雪人
下面k行,输出每个雪人的雪球半径。(由大到小,空格隔开)。
各个雪人的顺序不定。
若有多种情况,输出其一。【应该指代k相同的情况下,有多种情况】
分析:
代码如下:
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define rep(i,n) for (int i = 0; i < (n); ++i) 5 #define For(i,s,t) for (int i = (s); i <= (t); ++i) 6 #define rFor(i,t,s) for (int i = (t); i >= (s); --i) 7 #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) 8 #define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) 9 10 #define pr(x) cout << #x << " = " << x << " " 11 #define prln(x) cout << #x << " = " << x << endl 12 13 #define LOWBIT(x) ((x)&(-x)) 14 15 #define ALL(x) x.begin(),x.end() 16 #define INS(x) inserter(x,x.begin()) 17 18 #define ms0(a) memset(a,0,sizeof(a)) 19 #define msI(a) memset(a,inf,sizeof(a)) 20 #define msM(a) memset(a,-1,sizeof(a)) 21 22 #define pii pair<int,int> 23 #define piii pair<pair<int,int>,int> 24 #define mp make_pair 25 #define pb push_back 26 #define fi first 27 #define se second 28 29 inline int gc(){ 30 static const int BUF = 1e7; 31 static char buf[BUF], *bg = buf + BUF, *ed = bg; 32 33 if(bg == ed) fread(bg = buf, 1, BUF, stdin); 34 return *bg++; 35 } 36 37 inline int ri(){ 38 int x = 0, f = 1, c = gc(); 39 for(; c<48||c>57; f = c=='-'?-1:f, c=gc()); 40 for(; c>47&&c<58; x = x*10 + c - 48, c=gc()); 41 return x*f; 42 } 43 44 typedef long long LL; 45 typedef unsigned long long uLL; 46 const int inf = 1e9 + 9; 47 const LL mod = 1e9 + 7; 48 const int maxN = 1e5 + 7; 49 50 struct Node{ 51 int value, amount = 0; 52 53 inline bool operator < (const Node &x) const { 54 return amount < x.amount; 55 } 56 }; 57 58 int n, nlen, ans; 59 Node nodes[maxN]; 60 unordered_map< int, int > mii; 61 priority_queue< Node > maxH; 62 int Ans[maxN][3]; 63 64 int main(){ 65 while(cin >> n) { 66 mii.clear(); 67 nlen = 0; 68 rep(i, n) { 69 int t; 70 scanf("%d", &t); 71 if(mii.find(t) != mii.end()) { 72 ++nodes[mii[t]].amount; 73 } 74 else { 75 mii[t] = nlen; 76 nodes[nlen].value = t; 77 nodes[nlen++].amount = 1; 78 } 79 } 80 81 while(!maxH.empty()) maxH.pop(); 82 rep(i, nlen) maxH.push(nodes[i]); 83 84 ans = 0; 85 86 while(maxH.size() >= 3) { 87 Node a = maxH.top(); 88 maxH.pop(); 89 Node b = maxH.top(); 90 maxH.pop(); 91 Node c = maxH.top(); 92 maxH.pop(); 93 94 int x = min(min(a.value, b.value), c.value); 95 int z = max(max(a.value, b.value), c.value); 96 int y = a.value + b.value + c.value - x - z; 97 Ans[ans][0] = x; 98 Ans[ans][1] = y; 99 Ans[ans++][2] = z; 100 101 if(--a.amount) maxH.push(a); 102 if(--b.amount) maxH.push(b); 103 if(--c.amount) maxH.push(c); 104 } 105 cout << ans << endl; 106 107 rep(i, ans) printf("%d %d %d\n", Ans[i][2], Ans[i][1], Ans[i][0]); 108 } 109 return 0; 110 }
View Code
转载于:https://www.cnblogs.com/zaq19970105/p/10752658.html
CodeForces 140C New Year Snowm相关推荐
- 贪心(优先队列) - New Year Snowmen - CodeForces - 140C
贪心(优先队列) - New Year Snowmen - CodeForces - 140C 题意: 给定一个长度为n的正整数序列a1,a2,...,an.给定一个长度为n的正整数序列a_1,a_2 ...
- CodeForces - 140C New Year Snowmen
CodeForces - 140C New Year Snowmen 题意: 现在来做雪人,每个雪人由三个不同大小的雪球构成:一个大的,一个中等的,一个小的.现在有 n 个雪球半径分别为 r1, r2 ...
- New Year Snowmen codeforces 140C
题目 As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowme ...
- CodeForces 140C New Year Snowmen (贪心+优先队列)
题意:n个数,选三个严格下降的数为一组,求最多能选多少组,并列出每组哪些数. 题解:贪心+优先队列 最多能选多少组,那么必须贪心数量多的. 例如:1 1 2 3 4 5 如果按照数的大小排序,只能贪到 ...
- CodeForces 140C - New Year Snowmen(数据结构)
题目链接:click here~~ [题目大意]给你一个整数序列,求最多选出每个长度为3的且序列元素单调的子序列的个数,并且输出每个子序列的元素,作为一个子序列,每个元素只能选一次,也就是满足一次性, ...
- CodeForces 375D Tree and Queries
传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...
- 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)
题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...
- 【codeforces 812C】Sagheer and Nubian Market
[题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...
- CodeForces 获得数据
针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...
- codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...
题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...
最新文章
- HDU 4540 威威猫系列故事――打地鼠(DP)
- Intellij Idea 创建Web项目入门(一)
- linux:scp命令
- ECMAScript 对象类型
- android愤怒小鸟游戏、自定义View、掌上餐厅App、OpenGL自定义气泡、抖音电影滤镜效果等源码...
- 编译原理(简单自动词法分析器LEX)
- java程序员_Java和Python的区别 好程序员帮大家解读
- html定位 浏览器兼容,IE6浏览器不支持固定定位(position:fixed)解决方案
- 闺女在大连上大学,一个月1500生活费她说少
- delphi 获取打印机默认纸张_如何设置一台打印机打印不同尺寸的纸张
- 文本导入ORACLE快速,Oracle批量导入文本文件快速的方法(sqlldr实现)
- 关于SAS学习的记录
- matlab锁相放大器,锁相放大器原理和模块实现与仿真.DOC
- 联想 计算机无线网络设置方法,在Windows XP下如何配置无线网络
- 人脸识别与膜虹识别_虹膜识别技术优势明显 比指纹、人脸识别更可靠
- ubuntu使用cmake编译coffe
- Tilera 服务器上OpenJDK的安装尝试
- magisk安装失败_俄罗斯官改MIUI MiRoom安装刷入教程
- OpenCV读取图片
- idea的代码文本距离左边很远问题解决
热门文章
- 第二章 SQL命令参考-BEGIN
- 微信小程序实现随机标签云
- 发动机冒黑烟_发动机冒黑烟常见的23个原因和解决方法
- java 前后端分离教程,Java web前后端分离
- excel根据html生成表头c,excel表头的制作 怎样在Excel里面制作表头?
- 星期一到星期日的英文缩写「知识普及」
- 计算机等级考试报名被锁死,注册表被锁?教你解开的三种方法!
- 论文翻译:2021_Performance optimizations on deep noise suppression models
- 国内身份证号码的正则验证
- 失败的过去式英文翻译_过去式英语怎么说