Expedition---POJ - 2431
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<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn =1e5+;
int a[maxn],b[maxn];
int n,l,p; struct node{
int x,y;
}pp[maxn]; bool cmp(struct node a,struct node b){
return a.x<b.x;
} int main(){
cin>>n;
for( int i=; i<n; i++ ){
scanf("%d%d",&pp[i].x,&pp[i].y);
}
cin>>l>>p;
for( int i=; i<n; i++ ){
pp[i].x=l-pp[i].x;
}
sort(pp,pp+n,cmp); pp[n].x=l;
pp[n].y=; // for(int i=0; i<=n; i++){
// printf("%d ",pp[i].x);
// }
// cout<<endl;
// for(int i=0; i<=n; i++ ){
// printf("%d ",pp[i].y);
// }
// cout<<endl; priority_queue<int> que;
int ans=;//加油次数
int pos=;//当前位置
int tank=p;//汽油剩余量
b[n]=;
for(int i=; i<=n; i++ ){
int d=pp[i].x-pos;
// cout<<"d="<<d<<endl;
while(tank-d<){
if(que.empty()){
printf("-1\n");
return ;
}
tank+=que.top();
que.pop();
ans++;
// cout<<"+1"<<endl;
}
// cout<<"qian:"<<tank<<endl;
tank-=d;
// cout<<"hou:"<<tank<<endl;
pos=pp[i].x;
que.push(pp[i].y);
}
printf("%d\n",ans); return ;
}
Expedition---POJ - 2431的更多相关文章
- Heap:Expedition(POJ 2431)
远征队 题目大意:一部车要从一个地方走到另一个地方,开始的时候车的油箱有P升油,汽车每走1个距离消耗1升油,没有油汽车无法行驶,路上有加油站,可以为汽车加油,设汽车的油缸是无限大小的,问你汽车能否走到 ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- POJ 2431 Expedition (贪心+优先队列)
题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream&g ...
- poj 2431 【优先队列】
poj 2431 Description A group of cows grabbed a truck and ventured on an expedition deep into the jun ...
- POJ 2431 优先队列
汽车每过一单位消耗一单位油,其中有给定加油站可加油,问到达终点加油的最小次数. 做法很多的题,其中优先对列解这题是很经典的想法,枚举每个加油站,判断下当前油量是否小于0,小于0就在前面挑最大几个直至油 ...
- POJ 2431 Expedition (STL 优先权队列)
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8053 Accepted: 2359 Descri ...
- poj - 2431 Expedition (优先队列)
http://poj.org/problem?id=2431 你需要驾驶一辆卡车做一次长途旅行,但是卡车每走一单位就会消耗掉一单位的油,如果没有油就走不了,为了修复卡车,卡车需要被开到距离最近的城镇, ...
- POJ 2431 Expedition (贪心 + 优先队列)
题目链接:http://poj.org/problem?id=2431 题意:一辆卡车要行驶L单位距离,卡车上有P单位的汽油.一共有N个加油站,分别给出加油站距终点距离,及加油站可以加的油量.问卡车能 ...
- POJ 2431——Expedition(贪心,优先队列)
链接:http://poj.org/problem?id=2431 题解 #include<iostream> #include<algorithm> #include< ...
- poj 2431 Expedition 贪心 优先队列 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=2431 题解 朴素想法就是dfs 经过该点的时候决定是否加油 中间加了一点剪枝 如果加油次数已经比已知最少的加油次数要大或者等于了 那么就剪 ...
随机推荐
- jmeter测试报告分析
转载:http://www.cnblogs.com/miaomiaokaixin/p/6118081.html 在cmd中用命令行执行jmeter脚本: jmeter地址 -n -t 脚本地址 ...
- zabbix3.2自动发现批量监控redis端口状态
使用nmap提示被防火墙阻挡,实际没有启用防火墙 [root@eus_chinasoft_haproxy:/usr/local/aegis]# nmap 172.20.103.202 -p 7000 ...
- Node 环境变量 process.env.NODE_ENV 之webpack应用
转载来源:https://github.com/wfzong/NODE_ENV_TEST,这里还有源码可以学习,谢谢原作者的分享! 对于process.env.NODE_ENV困惑起因为在配置webp ...
- Java的慢和稳
对Java的了解还有待进一步提升,也没有做太多实践工作.只是把脑袋当成电脑,把Java放在里边不停地转,观察它的线路.得到的总体印象加上书本参考,认为Java的应用场景是慢和稳. 学编程语言总会接触到 ...
- 高可用Redis(二):字符串类型
1.Redis字符串结构 对于Redis来说,所有的key都是字符串,其value可以是string,list,hash,set,zset 比如下面的 键值对的value还可以更加复杂,比如可以是js ...
- P2255 [USACO14JAN]记录奥林比克
P2255 [USACO14JAN]记录奥林比克 题目描述 农民约翰热衷于所有寒冷天气的运动(尤其是涉及到牛的运动), 农民约翰想录下尽可能多的电视节目. 为moolympics电视时间表由N个不同的 ...
- SQL语句原理解析(原创)
基本的sql语句很好理解这里不做分析,这里只考虑复杂的sql语法和关键词用法的实验分析: 一,join关联的作用: 作用: 1,为了生成信息信息更加全面的中间表:2,为了where可以使用含有单表外字 ...
- htmlunit+fastjson抓取酷狗音乐 qq音乐链接及下载
上次学了jsoup之后,发现一些动态生成的网页内容是无法抓取的,于是又学习了htmlunit,下面是抓取酷狗音乐与qq音乐链接的例子: 酷狗音乐: import java.io.BufferedInp ...
- 解决exlipse下 springboot 错误:找不到或无法加载主类
简单描述:控制台出现了下图 废话不多说,直接上解决办法: 方法一:如果你很有自信,自己的pom 没问题,并且已经加载了所有依赖的jar.ok,这是eclipse的问题,window=>prefe ...
- VMware启动时提示我已移动或我已复制该虚拟机
参考地址:https://blog.csdn.net/luxiangzhou/article/details/79626113 1.VMware启动时提示“我已移动该虚拟机”或“我已复制该虚拟机”,选 ...