【POJ - 2431】Expedition(优先队列)
Expedition
直接中文
Descriptions
为了修理卡车,奶牛需要沿着一条蜿蜒的长路行驶到最近的城镇(距离不超过1,000,000个单位)。在这条路上,在城镇和卡车的当前位置之间,有N(1 <= N <= 10,000)燃料站,奶牛可以停下来获得额外的燃料(每站1..100个单位)。
丛林对人类来说是一个危险的地方,对奶牛尤其危险。因此,奶牛希望在前往城镇的路上尽可能少地停下燃料。幸运的是,他们的卡车上的油箱容量非常大,实际上它可以容纳的燃油量没有限制。卡车目前距离城镇L单位,有P单位的燃料(1 <= P <= 1,000,000)。
确定到达城镇所需的最小停留次数,或者奶牛根本无法到达城镇。
Input
*行2..N + 1:每行包含两个以空格分隔的整数,用于描述燃料停止:第一个整数是从城镇到停靠点的距离; 第二个是该站点可用的燃料量。
*行N + 2:两个以空格分隔的整数,L和P.
Output
Sample Input
4
4 4
5 2
11 5
15 10
25 10
Sample Output
22
Hint
卡车距离城镇25个单位; 这辆卡车有10个燃料单位。沿着这条路,距离城镇4,5,11和15的距离有4个燃料站(所以这些距离最初距离卡车的距离为21,20,14和10)。这些燃料停止装置可分别提供多达4个,2个,5个和10个单位的燃料。
输出细节:
驱动10个单位,停止再购买10个单位的燃料,再开4个单位,停止再购买5个单位的燃料,然后开车到镇上。
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 100000+5
using namespace std;
struct node
{
int dis;//距离
int value;//油
bool operator<(const node &c)const//按距离从大到小排序
{
return dis>c.dis;
}
};
node a[Maxn];
priority_queue<int>q;
int L,P,N;
int main()
{
cin>>N;
for(int i=;i<N;i++)
cin>>a[i].dis>>a[i].value;
cin>>L>>P;
sort(a,a+N);//排序
q.push(P);
int ans=,i=;
while(L>&&!q.empty())
{
ans++;//用了几个加油站
L-=q.top();
q.pop();
while(i<N&&L<=a[i].dis)//L<=a[i].dis,即进过加油站,存入队列
{
q.push(a[i].value);
i++;
}
}
if(L>)
cout<<-<<endl;
else
cout<<ans-<<endl;//第一次的油是自己的
return ;
}
【POJ - 2431】Expedition(优先队列)的更多相关文章
- poj 3431 Expedition 优先队列
poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...
- 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 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 贪心+优先队列 很好很好的一道题!!!
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10025 Accepted: 2918 Descr ...
- POJ 2431 Expedition (优先队列+贪心)
题目链接 Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. ...
- poj 2431 Expedition 贪心 优先队列 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=2431 题解 朴素想法就是dfs 经过该点的时候决定是否加油 中间加了一点剪枝 如果加油次数已经比已知最少的加油次数要大或者等于了 那么就剪 ...
随机推荐
- python 查询 elasticsearch 常用方法(Query DSL)
1. 建立连接 from elasticsearch import Elasticsearch es = Elasticsearch(["localhost:9200"]) 2. ...
- 浅入深出Vue:组件
组件在 vue开发中是必不可少的一环,用好组件这把屠龙刀,就能解决不少问题. 组件是什么 官方的定义: 组件是可复用的 Vue 实例,并且可带有一个名字. 官方的定义已经非常简明了,组件就是一个实例. ...
- Linux命令学习-cd命令
Linux中,cd命令的全称是change directory,即改变目录的意思,主要用于切换工作目录到指定目录. 假设当前处于wintest用户的主目录,路径为 /home/wintest ,存在文 ...
- JAVA面试题 浅析Java中的static关键字
面试官Q1:请说说static关键字,你在项目中是怎么使用的? static 关键字可以用来修饰:属性.方法.内部类.代码块: static 修饰的资源属于类级别,是全体对象实例共享的资源: 使用 s ...
- 微信小程序开发--组件(4)
一.picker-view / picker-view-column <view> <view>{{year}}年{{month}}月{{day}}日</view> ...
- blog更新
特别感谢: yu__xuan (啊这位着重感谢,多次帮助,于是帮他宣传一下https://www.cnblogs.com/poi-bolg-poi/) widerg 为两位大佬撒花~
- 2019年7月20日 - LeetCode0003
https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/submissions/ 我的解法: c ...
- SpringMvc返回JSON出现"$.result.currentLevel"
"$.result.currentLevel" 问题描述 使用SpringMvc返回一个json数据的时候,会在产生的结果中出现如下的问题:"$.result.curre ...
- 线程锁,threadinglocal,线程池,生产者消费者模型
1.线程锁 1.锁Lock(只能锁一次) import threading import time v = [] lock = threading.Lock() def func(arg): lock ...
- 盘一盘 synchronized (一)—— 从打印Java对象头说起
Java对象头的组成 Java对象的对象头由 mark word 和 klass pointer 两部分组成, mark word存储了同步状态.标识.hashcode.GC状态等等. klass ...