Expedition---POJ - 2431
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
* 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
Sample Input
4
4 4
5 2
11 5
15 10
25 10
Sample Output
2
Hint
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的更多相关文章
- Heap:Expedition(POJ 2431)
远征队 题目大意:一部车要从一个地方走到另一个地方,开始的时候车的油箱有P升油,汽车每走1个距离消耗1升油,没有油汽车无法行驶,路上有加油站,可以为汽车加油,设汽车的油缸是无限大小的,问你汽车能否走到 ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- POJ 2431 Expedition (贪心+优先队列)
题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream&g ...
- poj 2431 【优先队列】
poj 2431 Description A group of cows grabbed a truck and ventured on an expedition deep into the jun ...
- POJ 2431 优先队列
汽车每过一单位消耗一单位油,其中有给定加油站可加油,问到达终点加油的最小次数. 做法很多的题,其中优先对列解这题是很经典的想法,枚举每个加油站,判断下当前油量是否小于0,小于0就在前面挑最大几个直至油 ...
- 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 (贪心 + 优先队列)
题目链接: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 贪心 优先队列 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=2431 题解 朴素想法就是dfs 经过该点的时候决定是否加油 中间加了一点剪枝 如果加油次数已经比已知最少的加油次数要大或者等于了 那么就剪 ...
随机推荐
- hihocoder 1175
拓扑排序 hihocoder 1175 拓扑只适用于 有向无环图中,这个指的是 1.有向的,不是那种双向可走的 2.无环,并不是不存在环,而是一定要有一个没有其他点指向这个点的点, 题目大意:一个有向 ...
- [Kubernetes]说说 Service 与 Ingress
在 Kubernetes 中, Service 有三种对外暴露的方法,但是由于每个 Service 都要有一个负载均衡的服务,所以采用 Service 的话,会造成既浪费成本又高的现象.对于用户来说, ...
- WEB部分题目writeup
MEIZIJIU_PHP 题目链接: http://202.112.51.184:20001/ 打开网页出现一段PHP代码: 代码大意就是如果得到的code不为空则执行下列操作: 如果code长度大于 ...
- leveldb(ssdb)性能、使用场景评估
最近有个业务场景存储压力很大,写远远大于读,读也集中在最近写入,想想这不很适合采用leveldb存储么.leveldb的话好像用ssdb比较多,花了两天时间就ssdb简单做下测试,以下总结. ssdb ...
- java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.
java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.M ...
- Http协议入门、响应与请求行、HttpServletRequest对象的使用、请求参数获取和编码问题
1 课程回顾 web入门 1)web服务软件作用: 把本地资源共享给外部访问 2)tomcat服务器基本操作 : 启动: %tomcat%/bin/startup.bat 关闭: %tomcat%/ ...
- git 服务器 LINUX端的使用
首先,需要建立一个git服务器----- 这里介绍如何使用git这个服务器 我们在github上下载一份代码,里面有如下内容 我们使用git服务器的时候不能有.git 文件,所以在此将其删除 ys-l ...
- centos修改SSH端口并禁用root远程登录
1.使用 root 用户执行以下步骤:只在 CentOS 6.5 下验证. 2.先查看下服务器端口号范围: # sysctl -a|grep ip_local_port_range 3.修改端口 vi ...
- 安装Spotlight On Unix监控Linux
1.安装Spotlight 一步一步按提示安装即可- 2.安装sysstat 在Linux上,必须安装sysstat包,用户才可以获取详细的磁盘I/O信息. 执行 rpm -qa |grep syss ...
- 2018-2019-2 网络对抗技术 20165206 Exp2 后门原理与实践
- 2018-2019-2 网络对抗技术 20165206 Exp2 后门原理与实践 - 实验任务 (1)使用netcat获取主机操作Shell,cron启动 (0.5分) (2)使用socat获取主 ...