Expedition  点我
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9465   Accepted: 2760

Description

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 <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node
{
int a;
int b;
};
int cmp(node x,node y)
{
return x.a<=y.a;
}
int solve(int n)
{
priority_queue<int> s;
int i,pos=,tank=,ans=;
int dis;
node u[];
int L,P;
for(i=n-;i>=;i--)
cin>>u[i].a>>u[i].b;
cin>>L>>tank;
u[n].a=L;
u[n].b=;
for(i=;i<n;i++)
u[i].a=L-u[i].a;
sort(u,u+n,cmp);
for(i=;i<=n;i++)
{
dis=u[i].a-pos;
while(tank<dis)
{
if(s.empty())
{
cout<<-<<endl;
return ;
}
tank+=s.top();
s.pop();
ans++;
}
tank-=dis;
s.push(u[i].b);
pos=u[i].a;
}
cout<<ans<<endl;
return ;
}
int main()
{
int n;
//freopen("in","r",stdin);
while(cin>>n)
{
solve(n);
}
return ;
}

Expedition(优先队列)的更多相关文章

  1. poj 3431 Expedition 优先队列

    poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...

  2. H - Expedition 优先队列 贪心

    来源poj2431 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being ...

  3. EXPEDI - Expedition 优先队列

    题目描述 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rathe ...

  4. poj2431 Expedition优先队列

    Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Bein ...

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

    题目链接 Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. ...

  6. 【POJ - 2431】Expedition(优先队列)

    Expedition 直接中文 Descriptions 一群奶牛抓起一辆卡车,冒险进入丛林深处的探险队.作为相当差的司机,不幸的是,奶牛设法跑过一块岩石并刺破卡车的油箱.卡车现在每运行一个单位的距离 ...

  7. poj 2431 Expedition 贪心+优先队列 很好很好的一道题!!!

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10025   Accepted: 2918 Descr ...

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

    题目链接: 传送门 Expedition Time Limit: 1000MS     Memory Limit: 65536K 题目描述 驾驶一辆卡车行驶L单位距离.最开始有P单位的汽油.卡车每开1 ...

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

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

  10. POJ2431 Expedition(排序+优先队列)

    思路:先把加油站按升序排列. 在经过加油站时.往优先队列里增加B[i].(每经过一个加油站时,预存储一下油量) 当油箱空时:1.假设队列为空(能够理解成预存储的油量),则无法到达下一个加油站,更无法到 ...

随机推荐

  1. linux配置备忘

    ubuntu英文系统环境下,emacs输入中文设置:(http://www.cnblogs.com/pylemon/archive/2012/01/05/2312682.html) ~/.profil ...

  2. [bzoj 1001][Beijing2006]狼抓兔子 (最小割+对偶图+最短路)

    Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一 ...

  3. linux源码安装nodejs

    如何在linux上安装nodejs环境 到网下载安装文件node-v5.10.1-linux-x64.tar.gz.   将源码包上传到linux的/usr/local/node/目录下,在该目录下解 ...

  4. Windows 8.1 正式版镜像下载大全

    该系统已有更新的版本,请转至<Windows 8.1 with update 官方最新镜像汇总>下载. [声明:所有资源均来自于网络,请购买正版授权后再使用.]Win8.1 正式版原版镜像 ...

  5. 《Programming WPF》翻译 第8章 1.动画基础

    原文:<Programming WPF>翻译 第8章 1.动画基础 动画包括在一段时间内改变用户界面的某些可见的特征,如它的大小.位置或颜色.你可以做到这一点,非常困难的通过创建一个tim ...

  6. boost库使用:vs2013下boost::container::vector编译出错解决

    boost版本:boost_1_55_0 bug报告地址 https://svn.boost.org/trac/boost/ticket/9332 出错信息 has_member_function_c ...

  7. hdu 1429 胜利大逃亡(续)(bfs+状态压缩)

    Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带 ...

  8. python3-day1(基础总结)

    总结比较抽象的难点: 1.二进制运算 60 & 13  =12 60 |  13  =61 60 ^ 13  =49 60<<2   =240 60>>2   =15 ...

  9. Maven中pom.xml常用元素说明

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  10. 国内ip信息库的组建

    1.从 APNIC 分析得到国内的段 数据源位置:http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest 2.从QQ纯真库分析得到国 ...