Gym - 101806T: Touch The Sky(贪心)
Figure: The house floats up in the sky by balloons. This picture is also used in 2018 KAIST RUN Spring Contest poster.
In the year 2117, Professor Jaemin Yu developed a linear-time algorithm for TSP(Traveling Salesperson Problem). Not long after that happened, all computer systems were destroyed, and nuclear weapons demolished all the lands. You, a great computer expert, also lost your job. With a great despair, you lost your meaning of life long ago. All those things that made your heart beat – where had they gone? After questioning yourself again and again, your conclusion is ...
"If I go to KAIST where I started my first ICPC, can I find a meaning of my life?"
All transportations were destroyed, but you were an avid ICPC participant, and you collected a lot of century-old balloons in Korean Regionals. If you could float a house with some of those balloons...
Currently you have N balloons, and you are trying to float the house into the sky by attaching balloons on the rooftop. Every balloon have altitude limit Li and capacity Di, which indicates you can blow balloons in altitude at most Li, and the balloon busts after increasing the altitude by Di.
Your journey starts at altitude 0. If you have more than 1 balloons enlarged, then the house will ascend too fast. Thus, you will blow one balloon and attach it at the rooftop, increase the altitude until the balloons bust, blow the other balloon and attach it to increase the altitude... to make your house float. For convenience, you may assume that balloons can only increase the altitude.
You don't care about your final altitude, but a balloon can move a fixed amount of distance. Thus, you want to bust as many balloons as possible. You want to calculate a maximum number of balloons you can bust, and check if you can make a journey to KAIST. Let's see whether your 100-year-old ICPC experience can help on this problem!
The first line contains N, the number of balloons. (1 ≤ N ≤ 250, 000)
In next N lines, the altitude limit of i-th balloon Li, and capacity of i-th balloon Di are given as two space-separated integers. (0 ≤ Li ≤ 1015, 1 ≤ Di ≤ 109)
Output
Print the maximum number of balloons you can bust.
Examples
3
30 10
30 20
30 30
3
4
0 10
2 4
5 3
8 2
3
题意:现在有N个气球,第i个气球可以使用的条件是高度不大于Li,使用后高度会增加Di,问最多用多少个气球。
思路:这类题肯定是要先排序,然后贪心或者DP。 反正就是按Li和Di排序后都不好操作。 我们按照Li+Di排序,然后用一个大根堆,里面保存的是增加的高度。
如果当前高度大于Li,但是Di比较小,我们用它的Di去换大根堆里最大的一个。 这样是完全无后效性的。
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
priority_queue<int>q;
struct in{
ll x,y;
bool friend operator<(in w,in v){ return w.x<v.x; }
}s[];
int main()
{
int N; ll Now=; scanf("%d",&N);
rep(i,,N) {
scanf("%lld%lld",&s[i].x,&s[i].y);
s[i].x+=s[i].y;
}
sort(s+,s+N+);
rep(i,,N){
Now+=s[i].y; q.push(s[i].y);
if(Now>s[i].x){
Now-=q.top();
q.pop();
}
}
printf("%d\n",q.size());
return ;
}
Gym - 101806T: Touch The Sky(贪心)的更多相关文章
- Gym 101806T Touch The Sky
http://codeforces.com/gym/101806/problem/T 题目 In the year 2117, Professor Jaemin Yu developed a line ...
- codeforces gym #102082C Emergency Evacuation(贪心Orz)
题目链接: https://codeforces.com/gym/102082 题意: 在一个客车里面有$r$排座位,每排座位有$2s$个座位,中间一条走廊 有$p$个人在车内,求出所有人走出客车的最 ...
- Gym 101873K - You Are Fired - [贪心水题]
题目链接:http://codeforces.com/gym/101873/problem/K 题意: 现在给出 $n(1 \le n \le 1e4)$ 个员工,最多可以裁员 $k$ 人,名字为 $ ...
- Gym 100886J Sockets 二分答案 + 贪心
Description standard input/outputStatements Valera has only one electrical socket in his flat. He al ...
- Gym - 100283K K. Cubes Shuffling —— 贪心
题目链接:http://codeforces.com/gym/100283/problem/K 题解: 要使其相邻两项的差值之和最小,那么越靠中间,其数值越小. 那么剩下的问题就是如何放数字了.一开始 ...
- 2016"百度之星" - 初赛(Astar Round2A)1006 Gym Class(HDU5695)——贪心+拓扑排序
分析:首先,利用贪心可知,如果要所有人的分数和最高,需要把序号大的优先放在前面.其次,对于a的前面不能为b,那么只能a在b前面了,那么就建立一条从a到b的边,并且b的入度加1.然后就是拓扑排序了.要分 ...
- Gym 100507J Scarily interesting! (贪心)
Scarily interesting! 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/D Description This y ...
- CodeForces - 1013C C - Photo of The Sky 贪心
题目链接: https://vjudge.net/problem/1735276/origin 题目大意与思路: 题目的基本意思就是求一个矩形的最小面积. 这个可以用最大最小值, 将他们分为X和Y组. ...
- scala 学习笔记(06) OOP(下)多重继承 及 AOP
一.多继承 上篇trait中,已经看到了其用法十分灵活,可以借此实现类似"多重继承"的效果,语法格式为: class/trait A extends B with C with D ...
随机推荐
- stealwatch里的安全功能——ETA结果会显示加密套件以及key长度,还有流量大小(例如41MB)
以后可以考虑的方向,在stealwatch里包含: ad Injector click fraud cryptocurrency miner exploit kit malicious adverti ...
- python3+ftplib实现ftp客户端
一.程序说明 1.1 程序实现关键点 python实现ftp客户端,主要会遇到以下四个问题: 第一个问题是使用什么包实现----我们这里是使用标准库中的ftplib 第二个问题是怎么连接登录ftp服务 ...
- Linux升级内核教程(CentOS7)
1.查看当前内核版本 uname -r 2.通过yum升级内核 通过yum升级内核是最保险的升级方式,因为安装的是操作系统发行厂商验证过兼容性的rpm包,升级风险一般很小. yum install - ...
- 把旧系统迁移到.Net Core 2.0 日记(4) - 使用EF+Mysql
因为Mac 不能装SqlServer, 所以把数据库迁移到MySql,然后EntityFramework要改成Pomelo.EntityFrameworkCore.MySql 数据库迁移时,nvarc ...
- [Java] 各种流的分类及区别
https://www.cnblogs.com/lca1826/p/6427177.html 流在Java中是指计算中流动的缓冲区. 从外部设备流向中央处理器的数据流成为“输入流”,反之成为“输出流” ...
- 码云git使用一(上传本地项目到码云git服务器上)
主要讲下如果将项目部署到码云git服务器上,然后使用studio导入git项目,修改本地代码后,并同步到码云git上面. 首先:我们在码云上注册账号并登陆.官网(https://git.oschina ...
- OOP⑸
1.封装: 继承: extends java只支持单根继承!(一个类只能有一个直接的父类) 是代码重用的一种方式! 将子类共有的属性和方法提取到父类中去! Object:超类/基类==>java ...
- 2.19 C++友元函数和友元类
参考: http://www.weixueyuan.net/view/6350.html 总结: 借助friend关键字将其声明为友元函数,结果,在display函数体内,我们就能访问private属 ...
- Java基础-流程控制语句与运算符
运算符 算术运算符 ++ -- 在前时先运算后取值:在后时先取值后运算 关系运算符 == !=也可以是引用类型 位运算符 逻辑运算符 赋值运算符 条件运算符 (?:) 布尔表达式 ? 表达式1 : 表 ...
- SharePoint Framework 在Visual Studio Code中调试你的本地解决方案
博客地址:http://blog.csdn.net/FoxDave Visual Studio Code不知道大家都有没有,界面清爽,编辑快速,是一个非常好的前端开发工具.本文介绍如何使用Goog ...