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 ...
随机推荐
- mysql 查看mysql相关信息
登入数据库的时候: select @@version; select version(); 复制代码 mysql> select @@version; +-----------+ | @@ver ...
- (轉)JSON.stringify 语法实例讲解
作用:这个函数的作用主要是为了系列化对象的. 可能有些人对系列化这个词过敏,我的理解很简单.就是说把原来是对象的类型转换成字符串类型(或者更确切的说是json类型的).就这么简单.打个比方说,你有一个 ...
- oracle sqlplus操作
步骤: su - oracle 切换到oracle用户 sqlplus /nolog 进入sqlplus命令行 conn cps/cps 连接到cps用户的数据库,cps/cps表示:用户/密码 执行 ...
- Codeforces559C Gerald and Giant Chess
一道计数类\(DP\) 原题链接 我们可以先计算从左上角到右下角总的路径,再减去经过黑色方格的路径即是答案. 总路径数可以用组合数直接计算:\(C_{H+W-2}^{H-1}\) 因为从左上角到右下角 ...
- java 银联接口开发
http://blog.sina.com.cn/s/blog_6c868c470100ys59.html 在线接口文档:http://wenku.baidu.com/link?url=EUgAuOKz ...
- 使用Python完成排序(冒泡、选择、插入法)
class Sort(object): @staticmethod def bubble_sort(ls): lenth = len(ls) if lenth == 0: return [] whil ...
- 2019.01.13 bzoj1146: [CTSC2008]网络管理Network(整体二分+树剖)
传送门 题意简述:给一棵树,支持单点修改,询问路径上两点间第kkk大值. 思路: 读懂题之后立马可以想到序列上带修区间kkk大数的整体二分做法,就是用一个bitbitbit来支持查值. 那么这个题把树 ...
- 2018.12.31 NOIP训练 czy的后宫6(线性dp)
传送门 题意简述:给一个nnn个数的数列,你可以把它最多分成mmm段,求每段数之和的最大值的最小值,以及满足这个最小值的时候划分数列的方案数. 思路:第一个问题是二分经典问题,不妨设其答案为limli ...
- 2018.11.07 NOIP模拟 异或(数位dp)
传送门 对于每个二进制位单独考虑贡献. 然后对于两种情况分别统计. 对于第二种要用类似数位dpdpdp的方法来计算贡献. 代码
- 指令发布中如何实现new新消息的提醒?
设计思路:反馈后,最急需了解反馈结果的是申请人,故给每一条反馈信息添加一个查看状态的字段,如CK_STATUS,并为这个状态设计为char(1)类型,java bean中使用integer可以实现默认 ...