A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock and puncture the truck's fuel tank. The truck now leaks one unit of fuel every unit of distance it travels.

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

* Line 1: A single integer, N

* 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

* Line 1: A single integer giving the minimum number of fuel stops necessary to reach the town. If it is not possible to reach the town, output -1.

Sample Input

4
4 4
5 2
11 5
15 10
25 10

Sample Output

2

Hint

INPUT DETAILS:

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的更多相关文章

  1. Heap:Expedition(POJ 2431)

    远征队 题目大意:一部车要从一个地方走到另一个地方,开始的时候车的油箱有P升油,汽车每走1个距离消耗1升油,没有油汽车无法行驶,路上有加油站,可以为汽车加油,设汽车的油缸是无限大小的,问你汽车能否走到 ...

  2. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  3. POJ 2431 Expedition (贪心+优先队列)

    题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream&g ...

  4. poj 2431 【优先队列】

    poj 2431 Description A group of cows grabbed a truck and ventured on an expedition deep into the jun ...

  5. POJ 2431 优先队列

    汽车每过一单位消耗一单位油,其中有给定加油站可加油,问到达终点加油的最小次数. 做法很多的题,其中优先对列解这题是很经典的想法,枚举每个加油站,判断下当前油量是否小于0,小于0就在前面挑最大几个直至油 ...

  6. POJ 2431 Expedition (STL 优先权队列)

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8053   Accepted: 2359 Descri ...

  7. poj - 2431 Expedition (优先队列)

    http://poj.org/problem?id=2431 你需要驾驶一辆卡车做一次长途旅行,但是卡车每走一单位就会消耗掉一单位的油,如果没有油就走不了,为了修复卡车,卡车需要被开到距离最近的城镇, ...

  8. POJ 2431 Expedition (贪心 + 优先队列)

    题目链接:http://poj.org/problem?id=2431 题意:一辆卡车要行驶L单位距离,卡车上有P单位的汽油.一共有N个加油站,分别给出加油站距终点距离,及加油站可以加的油量.问卡车能 ...

  9. POJ 2431——Expedition(贪心,优先队列)

    链接:http://poj.org/problem?id=2431 题解 #include<iostream> #include<algorithm> #include< ...

  10. poj 2431 Expedition 贪心 优先队列 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=2431 题解 朴素想法就是dfs 经过该点的时候决定是否加油 中间加了一点剪枝 如果加油次数已经比已知最少的加油次数要大或者等于了 那么就剪 ...

随机推荐

  1. find 命令局部小结之 xtime

    大家在使用find命令的时候往往会使用它的 -name  或者 -xtime,在这里就说下他的xtime. find / -mtime +7 .find / -mtime -7.find / -mti ...

  2. 2019 icpc南昌全国邀请赛-网络选拔赛J题 树链剖分+离线询问

    链接:https://nanti.jisuanke.com/t/38229 题意: 给一棵树,多次查询,每次查询两点之间权值<=k的边个数 题解: 离线询问,树链剖分后bit维护有贡献的位置即可 ...

  3. Idea中一些常用设置

    idea展开和折叠方法的快捷键 Ctrl+”+/-”,当前方法展开.折叠Ctrl+Shift+”+/-”,全部展开.折叠 idea中也有自定代码块的功能 //region 描述.....业务代码//e ...

  4. 龙芯yl8089无声音的解决方案

    网上搜索到的解决方法都是卸载pulseaudio,但这种方法比较暴力不能从根本上解决问题. 经过一段时间的排查,我发现最终问题出现在resample-method上. 由于内核内CS5536 AC97 ...

  5. javascript任务队列

    摘自:https://www.cnblogs.com/liangyin/p/9783342.html,谢谢作者分享! 任务队列 所有任务可以分成两种,一种是 同步任务(synchronous),另一种 ...

  6. PCB开钢网不容忽视的问题

    作为PCB工程师,或许你已经出过很多次的钢网文件,但却不一定了解出钢网有哪些要求. 1.首先我们来看下钢网的实物图,就是一块薄薄的钢板,钢网上有很多焊盘孔.把钢网盖在PCB板上后,这些焊盘孔就会和PC ...

  7. python读取uti-8格式ini配置文件出现UnicodeDecodeError: 'gbk' codec can't decode byte 0xba in position 367: illegal multibyte sequence错误解决方法

    出现这种错误只需要在read下添加encoding='utf-8' 如: from configparser import ConfigParser cf = ConfigParser() cf.re ...

  8. Celery提交任务出错?

    跟着官方的入门教程部署和运行的,为啥报这个错? tasks.py # -*- encoding:UTF-8 -*- from celery import Celery brokers = 'redis ...

  9. Windows 2008 R2防火墙,允许被ping的设置方法

    这篇文章主要介绍了Windows 2008 R2防火墙,允许被ping的设置方法,需要的朋友可以参考下   1.准备 1)原因 出于安全因素考虑,在Windows 2008 R2上是不允许从外部对其P ...

  10. 2018-2019-2 20165328《网络对抗技术》Exp0 Kali安装week1

    1.下载Kaili安装资源并解压安装到虚拟机: 2.修改默认字体与共享文件设置: 3.更新软件源与下载中文输入法: 4.安装完成.