「CF140C」 New Year Snowmen
题目链接
贪心+优先队列,只要每次将数量前三大的半径拿出来就好了,用优先队列维护一下
#include<bits/stdc++.h>
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int read(){
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
return f*x;
}
struct hh{
int v,id;
bool operator < (hh a) const {
return v<a.v;
}
}a[100001];
struct node {
int x,y,z;
}c[100001];
int b[100001],d[100001];
priority_queue<hh> q;
int main(){
int n=read(),tot=1,cnt=0;
for(int i=1;i<=n;i++)
a[i].v=read(),a[i].id=i;
sort(a+1,a+1+n);
a[0].v=-2147483647;
for(int i=2;i<=n+1;i++){
if(a[i].v!=a[i-1].v){
hh now;
now.id=a[i-1].v,now.v=tot;
q.push(now),tot=1;
}
else
tot++;
}
hh now;
now=q.top();
int cc=0;
while(q.size()>=3){
hh now1,now2,now3;
now1=q.top(),q.pop();
now2=q.top(),q.pop();
now3=q.top(),q.pop();
now1.v--,now2.v--,now3.v--;
if(now1.v) q.push(now1),cc++;
if(now2.v) q.push(now2),cc++;
if(now3.v) q.push(now3),cc++;
c[++cnt].x=now1.id,c[cnt].y=now2.id,c[cnt].z=now3.id;
}
printf("%d\n",cnt);
for(int i=1;i<=cnt;i++){
int l=min(c[i].x,min(c[i].y,c[i].z)),r=max(c[i].x,max(c[i].y,c[i].z));
printf("%d ",r);
if(c[i].x<r&&c[i].x>l)
printf("%d ",c[i].x);
if(c[i].y<r&&c[i].y>l)
printf("%d ",c[i].y);
if(c[i].z<r&&c[i].z>l)
printf("%d ",c[i].z);
printf("%d\n",l);
}
return 0;
}
「CF140C」 New Year Snowmen的更多相关文章
- 「译」JUnit 5 系列:条件测试
原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...
- 「译」JUnit 5 系列:扩展模型(Extension Model)
原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...
- JavaScript OOP 之「创建对象」
工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...
- 「C++」理解智能指针
维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...
- 「JavaScript」四种跨域方式详解
超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...
- 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management
写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...
- 「2014-3-18」multi-pattern string match using aho-corasick
我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...
- 「2014-3-17」C pointer again …
记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...
- 「2014-3-13」Javascript Engine, Java VM, Python interpreter, PyPy – a glance
提要: url anchor (ajax) => javascript engine (1~4 articles) => java VM vs. python interpreter =& ...
随机推荐
- 子查询语句的thinkphp实现
语句 SELECT a.id as item_id,a.name as item_name,a.intro as item_intro,b.id,b.money FROM sh_incentive_i ...
- MySQL 优化器
(system@127.0.0.1:3306) [trunk]> show variables like '%performance_sch%';+----------------------- ...
- md5加密小程序
#-*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import hashlib m = hashlib.md5() m.updat ...
- 前端自动化之npm
npm——node依赖包管理工具 安装: 1.在nvm目录下复制npm和npm-cath文件夹 2.配置环境变量. 使用: 1.在项目文件夹,shift+右键打开命令窗口 2.npm init ...
- 「小程序JAVA实战」 小程序私有页面的生命周期以及导航(10)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-10/ 之前讲了小程序全局的生命周期,今天咱们说说单个页面的生命周期!源码:https://gith ...
- ubuntu14.10下Qt5.4无法输入中文
最近学习Qt,于是在ubuntu下安装了开发环境.我是从官网上下载安装的Qt5.4版本.安装后发现在开发过程中无法输入中文.于是在网上搜了搜.解决办法如下: 1.安装fcitx-frontend-qt ...
- Python基础学习五 内置函数
1.函数补充: 1)函数返回值return可以有多个 2)补充示例: nums = [0,1,2,3,4,5,6,7,8] #如何将list里面的元素变为字符串类型 new_nums = [str(x ...
- 安装oracle xe一些注意点
主要是web管理数据的的端口8080端口的问题, 会和tomcat冲突 安装时把开启8080端口的tomcat启动了 占用8080端口就行了, 然后安装oracle xe就会让你输入 web管理数据的 ...
- Areas in ASP.NET MVC 4
Download source - 2.7 MB Introduction to Areas In this article, we will learn the concept of Areas a ...
- ZOJ3953 Intervals
题意 有n个区间,要求删除一些区间使得不存在三个相交的区间.找出删除的最少区间. 分析 是个比较显然的贪心吧. 先按照区间的左起点进行排序,然后从左往右扫,当有三个区间相交的时候,删除那个右端点最远的 ...