POJ2431--Expedition(优先队列)
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<algorithm>
using namespace std;
struct node{
int dis;
int fuel;
bool operator<(const node& n)const{
return dis>n.dis;
}
}stop[];
int main(){
int n,l,p;
cin>>n;
priority_queue<int> que;
for(int i=;i<n;i++){
cin>>stop[i].dis>>stop[i].fuel;
}
cin>>l>>p;
int ans=;
que.push(p);
sort(stop,stop+n);
int t=;
while(l>&&!que.empty()){
int x=que.top();
que.pop();
l-=x;
ans++;
for(int i=t;i<n;i++){
if(l<=stop[t].dis){
que.push(stop[t].fuel);
t++;
}
}
}
if(l>)
cout<<-<<endl;
else
cout<<ans-<<endl;
return ;
}
POJ2431--Expedition(优先队列)的更多相关文章
- poj2431 Expedition优先队列
Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Bein ...
- poj 3431 Expedition 优先队列
poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...
- POJ2431 Expedition(排序+优先队列)
思路:先把加油站按升序排列. 在经过加油站时.往优先队列里增加B[i].(每经过一个加油站时,预存储一下油量) 当油箱空时:1.假设队列为空(能够理解成预存储的油量),则无法到达下一个加油站,更无法到 ...
- H - Expedition 优先队列 贪心
来源poj2431 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being ...
- poj2431(优先队列+贪心)
题目链接:http://poj.org/problem?id=2431 题目大意:一辆卡车,初始时,距离终点L,油量为P,在起点到终点途中有n个加油站,每个加油站油量有限,而卡车的油箱容量无限,卡车在 ...
- EXPEDI - Expedition 优先队列
题目描述 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rathe ...
- poj2431 Expedition
直接代码... #include<string.h> #include<stdio.h> #include<queue> #include<iostream& ...
- POJ2431 Expedition 贪心
正解:模拟费用流 解题报告: 先放个传送门鸭,题目大意可以点Descriptions的第二个切换成中文翻译 然后为了方便表述,这里强行改一下题意(问题是一样的只是表述不一样辣,,, 就是说现在在高速公 ...
- 【POJ - 2431】Expedition(优先队列)
Expedition 直接中文 Descriptions 一群奶牛抓起一辆卡车,冒险进入丛林深处的探险队.作为相当差的司机,不幸的是,奶牛设法跑过一块岩石并刺破卡车的油箱.卡车现在每运行一个单位的距离 ...
- POJ2431 优先队列+贪心 - biaobiao88
以下代码可对结构体数组中的元素进行排序,也差不多算是一个小小的模板了吧 #include<iostream> #include<algorithm> using namespa ...
随机推荐
- 关于PHP程序员技术职业生涯规划 2017年3月5日韩 天峰
看到很多PHP程序员职业规划的文章,都是直接上来就提Linux.PHP.MySQL.Nginx.Redis.Memcache.jQuery这些,然后就直接上手搭环境.做项目,中级就是学习各种PHP框架 ...
- 自适应手机网站meta name代码
<meta name="viewport" content="width=device-width,initial-scale=1.0"> co ...
- (转)system.badimageformatexception 未能加载文件或程序集
“/xxxxx”应用程序中的服务器错误. ------------------------------------------------------------------------------- ...
- js 立即执行函数
1.我们首先要搞明白:函数表达式和函数声明的区别. 函数表达式:既可以为匿名函数也可以有函数名,但是调用的时候都是通过函数左边的变量func来调用 var func = function(){ ale ...
- Linux入门命令1
查询及帮助 man查看命令帮助,命令的词典,显示Unix联机参考手册的页面 info从Info参考系统中显示文件 help查看Linux内置命令的帮助,比如cd命令. whatis 为指定命令显示一行 ...
- JavaScript中对数据库表中某一个字段进行赋值
场景如下,通过下拉列表选择一个选项(如“启用”和“不启用”),启用用0表示,不启用用1表示. enableFlag是表中一个字段,我猜date:后面就是对该字段的赋值.
- bowtie:短序列比对的新工具
bowtie:短序列比对的新工具(转) (2014-11-17 22:15:24) 转载▼ 标签: 转载 原文地址:bowtie:短序列比对的新工具(转)作者:玉琪星兆 Bowtie是一个超级快速 ...
- UI设计课程教程分享:Banner的设计和技巧
Banner是一个网站的中心主题,可以从banner看出网站的内容.所以一个好的banner对网站的影响很大. 提高banner的制作从几点深入了解:文字排版.选择适合的图片及背景.颜色的用法. 一. ...
- APICloud开发
2018-06-16 今天在看房角石APPIOS版本闪退的问题,后来定位到了 elements.find("video").attr("preload", &q ...
- vue 设置button disabled
<button v-bind:disabled="dis" @click="alert">button</button> dis:'' ...