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. docker保存日志文件到本地

    其实很简单 docker logs +你需要添加的额外参数 + 容器id >文件名称 然后查看这个文件就可以了,也可以通过ftp协议下载到本地

  2. anylogic 使用

    1.智能体群的用法有人会问:请问怎么给生成的两个对象赋予属性,比如在分叉的时候一个进入sink1,另一个进入sink2?我想source生成不同的实体,而且各个实体都有不同的属性,请问应该怎么设置呢? ...

  3. mybatis调用oracle存储过程的几个参考例子

    首先写一个存储过程: create or replace procedure p_syn_equipment_20161205 is sqlstr ); begin --清空表 sqlstr := ' ...

  4. safari下载中文文件名乱码

    原因:响应头设置content-disposition,主要遵循 RFC 5987标准. response.setHeader("content-disposition",&quo ...

  5. MariaDB存储过程笔记

    FECTH INTO 字段名不能与 CURSOR FOR 中select字段名一致,否则FETCH出的值均为空. DECLARE 字段名不能与 CURSOR FOR 中select语句内where条件 ...

  6. 利用android studio 生成 JNI需要的动态库so文件

    JNI:  Java Native Interface,  提供了java语言和其他语言(例如c和c++)进行相互调用的方式. 本文是用java调用c生成的so模式.其中,编译so文件过程如下: 1) ...

  7. 基于Spring Security OAuth2搭建的Spring Cloud 认证中心

    Github传送门:https://github.com/13babybear/bounter-springcloud 实现功能有: 整合JWT 刷新Token 自定义客户端储存 自定义用户储存 资源 ...

  8. OpenStack—nova组件计算服务

    nova介绍: Nova 是 OpenStack 最核心的服务,负责维护和管理云环境的计算资源.OpenStack 作为 IaaS 的云操作系统,虚拟机生命周期管理也就是通过 Nova 来实现的. 用 ...

  9. Rest分页接口开发

    简单描述:需求说后端写一个XX数据的分页接口,给前端口调用,其实有一个PageHelper的工具类可以直接使用但是老大不让用,得用sql写,.小Kiss啦.直接上代码 代码: //Controller ...

  10. 【svn】本地文件夹同步到SVN

    本地代码上传至SVN 起因: 我在开发项目代码时往往在本地开发很久,在基本功能完成时才上传svn,添加版本控制. 做法: 右键 TortoiseSVN - Repo browser 在希望项目存储的根 ...