CF140CNew Year Snowmen
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;
}
CF140CNew Year Snowmen的更多相关文章
- Day3-E-New Year Snowmen CodeForces140C
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. ...
- CoderForce 140C-New Year Snowmen(贪心)
题目大意:有n个已知半径的雪球.堆一个雪人需要三个尺寸不同的雪球,问用这些雪球最多能堆多少个雪人? 题目分析:先统计一下每种尺寸的球的个数,从三种最多的种类中各取出一个堆成雪人,这样贪心能保证的到的数 ...
- CodeForces 140C New Year Snowmen(堆)
题面 CodeForces 题解 因为要保证两两不同,所以不能单纯的开堆来维护,堆维护一个二元组,个数为第一关键字,编号为第二关键字,对于一个相同的颜色,统计一下这个颜色的个数再用堆来维护就好了. # ...
- 「CF140C」 New Year Snowmen
题目链接 戳这 贪心+优先队列,只要每次将数量前三大的半径拿出来就好了,用优先队列维护一下 #include<bits/stdc++.h> #define rg register #def ...
- [Codeforces 140C] New Year Snowmen
[题目链接] https://codeforces.com/problemset/problem/140/C [算法] 显然 , 我们每次应优先考虑数量多的雪球 将雪球个数加入堆中 , 每次取出数量前 ...
- 【Codeforces 140C】New Year Snowmen
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 每次都选择剩余个数最多的3个不同数字组成一组. 优先消耗剩余个数多的数字 这样能尽量让剩余的数字总数比较多,从而更加可能得到更多的3个组合 [ ...
- CF140C New Year Snowmen
题目链接 这道题其实吧,水,我们教练说过,不要看标签,这只是CSP第一题的题目 思路嘛,priority_queue和贪心,就这样,很水 这是代码 还有,一定要在cf上交,不然--可以看一下提交记录, ...
- CF140C New Year Snowmen(贪心+优先队列)
CF140C 贪心+优先队列 贪心策略:每次取出数量最多的三种球,合成一个答案,再把雪球数都-1再插回去,只要还剩下三种雪球就可以不断地合成 雪球数用优先队列维护 #include <bits/ ...
- CodeForces #100 C 贪心+STL
题目链接:CodeForces #100 C 题意:现在给出n个snowball的半径,3个半径严格递增或递减的snowball,可以组成1个snowmen.问最多能组成多少个snowmen.并且按 ...
随机推荐
- oracle-ORA-01555错误
Snapshot too old 原因:没有足够的撤销空间满足读一致性而需要撤销信息的长查询
- LeetCode21 Merge Two Sorted Lists
题意: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...
- Python3 写的远程批量修改文件内容的脚本
一.说明: 1.利用Python的paramiko模块,调用远程的shell命令去修改相应文件. 2.有一个专用配置文件,列出服务器清单. 3.Python循环读取配置文件的服务器IP去连接它,并执行 ...
- @游记@ CSP2019
目录 @day -??@ @day -1@ @day 0@ @day 1@ @day 2@ @day ??@ @day ??+1@ @day -??@ 和 yhn 学长在校外偶遇. 聊了一些.他说现在 ...
- CSS Specificity
CSS的specificity特性或称非凡性,它是一个衡量CSS值优先级的一个标准. 其实就是解决冲突,当同一个元素被CSS选择符选中,按照优先权取舍不同的CSS规则. specificity用一个四 ...
- 原生js复习1.0
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- LeetCode67 Add Binary
题目: Given two binary strings, return their sum (also a binary string). (Easy) For example,a = " ...
- MapReduce数据流-概述
- "不用谢" 的11种表达
说Thank you ,机械版的反应you are welcome.虽然没错,但实在太老掉牙,在国外使用率不高: 随性,不足挂齿的小事 Not a problem 别放在心上 Any time 有事随 ...
- Android ListView批量选择(全选、反选、全不选)
APP的开发中,会常遇到这样的需求:批量取消(删除)List中的数据.这就要求ListVIew支持批量选择.全选.单选等等功能,做一个比较强大的ListView批量选择功能是很有必要的,那如何做呢? ...