Expedition

Time Limit: 1000MS Memory Limit: 65536K

Total Submissions: 20089 Accepted: 5786

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.


解题心得

  1. 做这个题是看了挑战那本书才来做的题,结果只是考了一个很简单的思维问题,但是被poj上的题目描述和挑战那本书的题目描述给弄晕了,poj是反着描述的,但是挑战那本书是正向描述的。sad。
  2. 怎么解题挑战那本书上面说的很清楚了就不多说了。

#include <stdio.h>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn = 1e4+100;
int l,now,res,n;
struct NODE {
int va,pos;
friend bool operator < (const NODE a,const NODE b){
return a.pos < b.pos;
}
}node[maxn]; void init() {
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&node[i].pos,&node[i].va);
scanf("%d%d",&l,&res);
node[n].va = 0;
node[n].pos = l;
for(int i=0;i<n;i++)
node[i].pos = l - node[i].pos;//反向输入的位置给弄正 sort(node,node+n+1);
now = 0;
} void solve() {
int ans = 0;
priority_queue <int> qu; for(int i=0;i<=n;i++) {
int dis = node[i].pos - now;
while(dis > res) {
if(qu.empty()){
printf("-1");
return ;
}
res += qu.top();
ans++;
qu.pop();
}
qu.push(node[i].va);
now = node[i].pos;
res -= dis;
}
printf("%d",ans);
} int main() {
init();
solve();
return 0;
}

POJ:2431-Expedition的更多相关文章

  1. POJ 2431 Expedition(探险)

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

  2. poj:4091:The Closest M Points

    poj:4091:The Closest M Points 题目 描写叙述 每到饭点,就又到了一日几度的小L纠结去哪吃饭的时候了.由于有太多太多好吃的地方能够去吃,而小L又比較懒不想走太远,所以小L会 ...

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

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

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

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

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

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

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

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

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

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

  8. poj 2431 Expedition

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12980   Accepted: 3705 Descr ...

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

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

  10. POJ 2431 Expedition (priority_queue或者multiset可解)

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18655   Accepted: 5405 Descr ...

随机推荐

  1. JSON FILE NOT FOUND?

    (WIN7+IIS7) 搞一个小测试,一个小程序,用一个JSON文件来显示数据, 用HTML 访问是完全没有问题的,可是一放到IIS下,就出现无法访问, CONSOLE:提示  NOT FOUND 原 ...

  2. 切图让我进步!关于white-space属性的组合拳

    菜鸟一枚,没有大神的风骚,只有一点在练习中的心得,今天获得的知识是关于white-space属性.overflow属性还有text-overflow属性的组合使用,废话不多说浪费时间,进入今天的正题! ...

  3. C#设计模式--适配器模式(结构型模式)

    一.适配器模式介绍: 适配器模式:将一个类的接口,转换成客户希望的另外一个接口.adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作 例子分析(充电器充电): 模式中的角色: 安 ...

  4. Zamplus 晶赞天机

    类型: 定制服务 软件包: car/vehicle integrated industry solution collateral tourism 联系服务商 产品详情 解决方案 概要 DMP:通常称 ...

  5. powershell解决win10开始菜单和通知中心无法打开

    然后通过 Ctrl + Shift + Esc 弹出任务管理器点击文件-->运行新任务 在打开的填写框里面输入 "powershell"同时勾选下方的"以管理员身份 ...

  6. Windows计算下载文件的SHA256 MD5 SHA1

    引用自 http://blog.163.com/licanli2082@126/blog/static/35748686201284611330/ certutil -hashfile yourfil ...

  7. 如何把某个网站的SSL Server certificate链导入到ABAP Netweaver系统里

    我们在用ABAP代码消费外网的url时会遇到一些异常,比如ICM_HTTP_SSL_PEER_CERT_UNTRUSTED,这是因为请求的url所在的网站的SSL Server certificate ...

  8. Uva 12657 双向链表

    题目链接:https://uva.onlinejudge.org/external/126/12657.pdf 题意: 给你一个从1~n的数,然后给你操作方案 • 1 X Y : move box X ...

  9. ssh key一键自动化生成公钥私钥,并自动分发上百服务器免密码交互

    题记:由于工作需要管理大量服务器,所以需要配公钥实现免密登录. ssh批量分发可以一键执行这个操作,但是使用ssh分发服务还需要对各个服务器进行.ssh/id_dsa.pub公钥上传,密码验证.所以需 ...

  10. Linux 初学者:移动文件

    你学习了有关目录和访问目录的权限是如何工作的.你在这些文章中学习的大多数内容都可应用于文件 -- Paul Brown 在之前的该系列的部分中, 你学习了有关目录 和 访问目录 的权限 是如何工作的. ...