CF140C New Year Snowmen
这道题其实吧,水,我们教练说过,不要看标签,这只是CSP第一题的题目
思路嘛,priority_queue和贪心,就这样,很水
这是代码
还有,一定要在cf上交,不然……可以看一下提交记录,有几个人的代码回来了
Code
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
const int MAXN = 1e6 + 5;
inline int read(){
int k = 0,f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-'){
f = -1;
}
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
k = k * 10 + ch - '0';
ch = getchar();
}
return k * f;
}
inline void write(int x){
if (x < 0){
putchar('-');
x = -x;
}
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
struct node{
int cnt,num,id;
node(){}
node(int Cnt,int Num){
cnt = Cnt,num = Num;
}
bool operator <(const node& a) const{
return cnt < a.cnt;
}
}a[MAXN];
priority_queue <node> q;
int cnt = 1;
int ans;
struct ball{
int big,mid,sma;
}k[MAXN];
bool cmp(node x,node y){
return x.num < y.num;
}
int main(){
int n;
n = read();
for (int i = 1; i <= n ; i++) a[i].num = read();
sort(a + 1,a + 1 + n,cmp);
for (int i = 1; i <= n; i++){
if (a[i].num != a[i + 1].num){
q.push(node(cnt,a[i].num));
cnt = 1;
}
else cnt++;
}
if (q.size() < 3){
printf("0");
return 0;
}
while(q.size() >= 2){
node x = q.top();q.pop();
node y = q.top();q.pop();
node z = q.top();q.pop();
x.cnt--,y.cnt--,z.cnt--;
k[++ans].big = x.num;
k[ans].mid = y.num;
k[ans].sma = z.num;
if (x.cnt) q.push(node(x.cnt,x.num));
if (y.cnt) q.push(node(y.cnt,y.num));
if (z.cnt) q.push(node(z.cnt,z.num));
}
write(ans);
putchar(10);
for (int i = 1 ; i <= ans ; i++){
int m[5];
m[1] = k[i].big;
m[2] = k[i].mid;
m[3] = k[i].sma;
sort(m + 1,m + 4);
printf("%d %d %d\n",m[3],m[2],m[1]);
}
return 0;
}
CF140C New Year Snowmen的更多相关文章
- CF140C New Year Snowmen(贪心+优先队列)
CF140C 贪心+优先队列 贪心策略:每次取出数量最多的三种球,合成一个答案,再把雪球数都-1再插回去,只要还剩下三种雪球就可以不断地合成 雪球数用优先队列维护 #include <bits/ ...
- 钠 GZY整理贪心
目录 CF140C New Year Snowmen CF161B Discounts P1842 奶牛玩杂技 CF140C New Year Snowmen #include <bits/st ...
- 「CF140C」 New Year Snowmen
题目链接 戳这 贪心+优先队列,只要每次将数量前三大的半径拿出来就好了,用优先队列维护一下 #include<bits/stdc++.h> #define rg register #def ...
- CF140CNew Year Snowmen
CF140C 题目大意:堆雪人,需要三个大小不同的雪球,现有\(n\)个给定大小的雪球,问最多堆多少个雪人 一个很明显的思路是把每种雪球出现的个数记录下来,然后直接扔到大根堆里面,每次选择剩下出现次数 ...
- 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 题解 因为要保证两两不同,所以不能单纯的开堆来维护,堆维护一个二元组,个数为第一关键字,编号为第二关键字,对于一个相同的颜色,统计一下这个颜色的个数再用堆来维护就好了. # ...
- [Codeforces 140C] New Year Snowmen
[题目链接] https://codeforces.com/problemset/problem/140/C [算法] 显然 , 我们每次应优先考虑数量多的雪球 将雪球个数加入堆中 , 每次取出数量前 ...
- 【Codeforces 140C】New Year Snowmen
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 每次都选择剩余个数最多的3个不同数字组成一组. 优先消耗剩余个数多的数字 这样能尽量让剩余的数字总数比较多,从而更加可能得到更多的3个组合 [ ...
随机推荐
- 搞IT产品,请谨记Mobile First
我们在哪儿? 作为一名企业IT的老鸟,发现一个比较有意思的事情,就是我们的企业IT产品,仍然投入大量的精力,在基于PC的WEB端的设计和交付上,而在APP上的,移动端的考虑,一直都是在PC搞完之后,再 ...
- OCR文字识别在计算机视觉的重要性、基本技术和最新进展
[摘要] 主要是文字检测和文字识别作为计算机视觉一部分的重要性,基本知识,面临的挑战,以及部分最新的成果. 人类认识了解世界的信息中91%来自视觉,同样计算机视觉成为机器认知世界的基础,也是人工智能研 ...
- springboot整合thymleaf模板引擎
thymeleaf作为springboot官方推荐使用的模板引擎,简单易上手,功能强大,thymeleaf的功能和jsp有许多相似之处,两者都属于服务器端渲染技术,但thymeleaf比jsp的功能更 ...
- luogu P3572 [POI2014]PTA-Little Bird |单调队列
从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制,求每次最少耗费多少体力 #include<cstdio> #include<cstring> #i ...
- echarts 堆叠柱状图 + 渐变柱状图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 回文自动机pam
目的:类似回文Trie树+ac自动机,可以用来统计一些其他的回文串相关的量 复杂度:O(nlogn) https://blog.csdn.net/Lolierl/article/details/999 ...
- CoderForces 163E e-Government(AC自动机+树状数组维护fail树的dfs序)
E. e-Government time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- CoderForces Round60-(1117A,1117B,1117C题解)
A. Best Subsegment time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- HDU5394 Bomb
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5934 There are NN bombs needing exploding. Each bomb ha ...
- JSP+Servlet 实现:理财产品信息管理系统
一.接业务,作分析 1.大致业务要求 1.1 使用 JSP+Servlet 实现理财产品信息管理系统,MySQL5.5 作为后台数据库,实现查看理财 和增加理财功能 1.2 查询页面效果图 1.3 添 ...