Expedition(优先队列)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9465 | Accepted: 2760 |
Description
To repair the truck, the cows need to drive to the nearest town (no more than 1,000,000 units distant) down a long, winding road. On this road, between the town and the current location of the truck, there are N (1 <= N <= 10,000) fuel stops where the cows can stop to acquire additional fuel (1..100 units at each stop).
The jungle is a dangerous place for humans and is especially dangerous for cows. Therefore, the cows want to make the minimum possible number of stops for fuel on the way to the town. Fortunately, the capacity of the fuel tank on their truck is so large that there is effectively no limit to the amount of fuel it can hold. The truck is currently L units away from the town and has P units of fuel (1 <= P <= 1,000,000).
Determine the minimum number of stops needed to reach the town, or if the cows cannot reach the town at all.
Input
* Lines 2..N+1: Each line contains two space-separated integers describing a fuel stop: The first integer is the distance from the town to the stop; the second is the amount of fuel available at that stop.
* Line N+2: Two space-separated integers, L and P
Output
Sample Input
4
4 4
5 2
11 5
15 10
25 10
Sample Output
2
Hint
The truck is 25 units away from the town; the truck has 10 units of fuel. Along the road, there are 4 fuel stops at distances 4, 5, 11, and 15 from the town (so these are initially at distances 21, 20, 14, and 10 from the truck). These fuel stops can supply up to 4, 2, 5, and 10 units of fuel, respectively.
OUTPUT DETAILS:
Drive 10 units, stop to acquire 10 more units of fuel, drive 4 more units, stop to acquire 5 more units of fuel, then drive to the town.
#include <iostream>
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node
{
int a;
int b;
};
int cmp(node x,node y)
{
return x.a<=y.a;
}
int solve(int n)
{
priority_queue<int> s;
int i,pos=,tank=,ans=;
int dis;
node u[];
int L,P;
for(i=n-;i>=;i--)
cin>>u[i].a>>u[i].b;
cin>>L>>tank;
u[n].a=L;
u[n].b=;
for(i=;i<n;i++)
u[i].a=L-u[i].a;
sort(u,u+n,cmp);
for(i=;i<=n;i++)
{
dis=u[i].a-pos;
while(tank<dis)
{
if(s.empty())
{
cout<<-<<endl;
return ;
}
tank+=s.top();
s.pop();
ans++;
}
tank-=dis;
s.push(u[i].b);
pos=u[i].a;
}
cout<<ans<<endl;
return ;
}
int main()
{
int n;
//freopen("in","r",stdin);
while(cin>>n)
{
solve(n);
}
return ;
}
Expedition(优先队列)的更多相关文章
- poj 3431 Expedition 优先队列
poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...
- H - Expedition 优先队列 贪心
来源poj2431 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being ...
- EXPEDI - Expedition 优先队列
题目描述 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rathe ...
- poj2431 Expedition优先队列
Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Bein ...
- POJ 2431 Expedition (优先队列+贪心)
题目链接 Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. ...
- 【POJ - 2431】Expedition(优先队列)
Expedition 直接中文 Descriptions 一群奶牛抓起一辆卡车,冒险进入丛林深处的探险队.作为相当差的司机,不幸的是,奶牛设法跑过一块岩石并刺破卡车的油箱.卡车现在每运行一个单位的距离 ...
- poj 2431 Expedition 贪心+优先队列 很好很好的一道题!!!
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10025 Accepted: 2918 Descr ...
- POJ 2431 Expedition(优先队列、贪心)
题目链接: 传送门 Expedition Time Limit: 1000MS Memory Limit: 65536K 题目描述 驾驶一辆卡车行驶L单位距离.最开始有P单位的汽油.卡车每开1 ...
- poj - 2431 Expedition (优先队列)
http://poj.org/problem?id=2431 你需要驾驶一辆卡车做一次长途旅行,但是卡车每走一单位就会消耗掉一单位的油,如果没有油就走不了,为了修复卡车,卡车需要被开到距离最近的城镇, ...
- POJ2431 Expedition(排序+优先队列)
思路:先把加油站按升序排列. 在经过加油站时.往优先队列里增加B[i].(每经过一个加油站时,预存储一下油量) 当油箱空时:1.假设队列为空(能够理解成预存储的油量),则无法到达下一个加油站,更无法到 ...
随机推荐
- Loadrunner根据PV量来确定需要进行压测的并发量
在实际做压力测试的过程中,我们有时不知道用怎样的并发量比较好,下面是几个用PV量去确定并发量的公式,这个在我们公司是比较适用的,大家可以根据自己的业务进行运算. 方法一:这个方法是我在网上查到的80- ...
- npm install 本地安装与全局安装
npm的包安装分为本地安装(local).全局安装(global)两种,从敲的命令行来看,差别只是有没有-g而已: npm install grunt # 本地安装 npm install -g gr ...
- Silverlight信息加密 - 通过Rfc2898DeriveBytes类使用基于HMACSHA1的伪随机数生成器实现PBKDF2
原文: http://blog.csdn.net/xuyue1987/article/details/6706600 在上一篇文章当中,介绍到了通过Silverlight获取web.config中的值 ...
- Could not open a connection to your authentication agent
执行ssh-add ~/.ssh/rsa 就会遇到上述错误了 解决方案: 先执行 eval `ssh-agent` (是-键上的那个`) 再执行 ssh-add ~/.ssh/rsa成功 ssh ...
- 利用jquery表格添加一行并在每行第一列大写字母显示实现方法
表格添加一行并在每行第一列大写字母显示jquery实现方法 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN& ...
- HDU 1576 A/B(数论)
题目:求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1).数据给出n和b 推导过程 A/B = K K = 9973* ...
- 关于NetBeans IDE的配置优化
首先,IDE的版本最好对应着JDK的版本. NetBeans优化的目的是提高NetBeans的启动速度和运行速度.下面介绍的NetBeans优化技巧是在版本6.0beta2上的优化.经过实验,大大提高 ...
- Timer.5 - Synchronising handlers in multithreaded programs
This tutorial demonstrates the use of the boost::asio::strand class to synchronise callback handlers ...
- ORACLE 视图的 with check option
ORACLE 视图的 with check option 我们来看下面的例子: create or replace view testview as select empno,ename from e ...
- zabbix-web界面图形中文乱码解决方法
1.搜索windows-server X86-64机器上C:/windows/fonts的simkai.tts文件,windows7下有时候不行. 2.把它拷贝到zabbix的web端的fonts目录 ...