POJ:2431-Expedition
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.
解题心得
- 做这个题是看了挑战那本书才来做的题,结果只是考了一个很简单的思维问题,但是被poj上的题目描述和挑战那本书的题目描述给弄晕了,poj是反着描述的,但是挑战那本书是正向描述的。sad。
- 怎么解题挑战那本书上面说的很清楚了就不多说了。
#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的更多相关文章
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- poj:4091:The Closest M Points
poj:4091:The Closest M Points 题目 描写叙述 每到饭点,就又到了一日几度的小L纠结去哪吃饭的时候了.由于有太多太多好吃的地方能够去吃,而小L又比較懒不想走太远,所以小L会 ...
- POJ 2431 Expedition (STL 优先权队列)
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8053 Accepted: 2359 Descri ...
- poj - 2431 Expedition (优先队列)
http://poj.org/problem?id=2431 你需要驾驶一辆卡车做一次长途旅行,但是卡车每走一单位就会消耗掉一单位的油,如果没有油就走不了,为了修复卡车,卡车需要被开到距离最近的城镇, ...
- POJ 2431 Expedition (贪心+优先队列)
题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream&g ...
- POJ 2431 Expedition (贪心 + 优先队列)
题目链接:http://poj.org/problem?id=2431 题意:一辆卡车要行驶L单位距离,卡车上有P单位的汽油.一共有N个加油站,分别给出加油站距终点距离,及加油站可以加的油量.问卡车能 ...
- POJ 2431——Expedition(贪心,优先队列)
链接:http://poj.org/problem?id=2431 题解 #include<iostream> #include<algorithm> #include< ...
- poj 2431 Expedition
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12980 Accepted: 3705 Descr ...
- POJ 2431 Expedition (优先队列+贪心)
题目链接 Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. ...
- POJ 2431 Expedition (priority_queue或者multiset可解)
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18655 Accepted: 5405 Descr ...
随机推荐
- java分页三个类 PageBean ResponseUtil StringUtil
package ssmy.page; /** * 分页类 * @author Jesse * */public class PageBean { private int page;//第几页 priv ...
- em和rem的区别
rem和em单位一样,都是一个相对单位,不同的是em是相对于元素的父元素的font-size进行计算,rem是相对于根元素html的font-size进行计算,这样一来rem就绕开了复杂的层级关系,实 ...
- 腾讯bugly 映射用法
package com.tencent.bugly.agent; import android.app.Activity; import android.content.Context; import ...
- Springboot开源项目实例整理
https://www.imooc.com/article/67664 ---------------------------------------------------------------- ...
- SuiteCRM-7.7.6 (Ubuntu 16.04)
平台: Ubuntu 类型: 虚拟机镜像 软件包: suitecrm-7.7.6 commercial crm open-source suitecrm 服务优惠价: 按服务商许可协议 云服务器费用: ...
- 深入了解MongoDB
一.介绍: 数据库分为关系型数据库和非关系型数据库 关系型数据库是建立在关系模型上的数据库,主要的有Oracle MySQL Microsoft SQL Server NoSQL是非关系型数据存储的广 ...
- *389. Find the Difference (string + map(26)) read problems carefully
Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...
- 关于使用Encoding转码的问题,以及StreamWriter的小应用
StreamWriter write = new StreamWriter("../../test2.txt"); write.WriteLine("中国123巴西red ...
- Poj(2225),三维BFS
题目链接:http://poj.org/problem?id=2225 这里要注意的是,输入的是坐标x,y,z,那么这个点就是在y行,x列,z层上. 我竟然WA在了结束搜索上了,写成了输出s.step ...
- 整个trick
数据输入方面:1.image pyramid 图像金字塔.目前代码里是先选取一个scale,然后在每个GPU上按照scale读图片,相应的gt也更改."scales":[440, ...