https://vjudge.net/contest/393971#overview

http://poj.org/problem?id=2431

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 <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
#define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl; #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
const int N=1e6+10;
const int mod=1e9+7; struct node
{
int dis,fuel;
}stop[10005];
bool cmp(node x,node y)
{
return x.dis > y.dis;
}
int main()
{
int n = 0;
int L = 0 , P = 0;
int counter = -1;
cin >> n;
priority_queue<int> Q;
for(int i = 0;i<n;i++)
{
cin >> stop[i].dis >> stop[i].fuel;
}
sort(stop,stop+n,cmp);
cin >> L >> P; Q.push(P);
int p = 0;
while(L > 0 && !Q.empty())
{
int spent = Q.top();
Q.pop();
L -= spent;
while(p < n)
{
if(L <= stop[p].dis)
{
Q.push(stop[p].fuel);
p++;
}
else
{
break;
}
}
counter += 1;
}
if(L <= 0)
{
cout << counter <<endl;
}
else
{
cout << -1 <<endl;
}
return 0;
}

  

A - Expedition的更多相关文章

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

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

  2. POJ 2431 Expedition(探险)

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

  3. poj 2431 Expedition

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

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

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

  5. Expedition(优先队列)

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

  6. poj 3431 Expedition 优先队列

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

  7. CF1091F New Year and the Mallard Expedition

    题目地址:CF1091F New Year and the Mallard Expedition 题意比较复杂,整理一下: \(n\) 段,每段有两个属性:长度,地形(G,W,L) 有三种运动方式: ...

  8. H - Expedition 优先队列 贪心

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

  9. Planning The Expedition(暴力枚举+map迭代器)

    Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...

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

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

随机推荐

  1. Web安全入门学习--攻防世界web安全新手区过关心得

    这几天也是废了小小功夫,完成了这十道题目. 这十道题目说难不难,说简单对刚入门的同学来说也没有那么简单,但是做完可以对web有最初步的了解 下面开始解题 1.view_source 作为第一题,这题还 ...

  2. 利用 SSE 实现流式 AI 聊天交互(三)

    在 AI 赋能的时代,即时交互式对话体验成为众多应用的核心功能之一.本文将介绍如何使用 流式 SSE (Server-Sent Events) 技术,实现高效的 AI 聊天交互,提供更加丝滑的用户体验 ...

  3. Js RSA非对称加密

    // RSA 加密 async function encryptData(publicKeyStr, data) { const publicKey = await importPublicKey(p ...

  4. python 利用librosa库变声,声音变速

    wav文件可自定义,将wav文件放置在代码的同一目录下 文件要改名为gg. wav 声音变速: import librosa y,sr = librosa.load("gg.wav" ...

  5. 你应该懂的AI大模型(三)之 RAG

    从本篇开始笔者会尽量多使用一些英文缩写和单词,不是笔者为了装X,是为了大家在后面遇到的时候不至于被别人装到. 一.什么是RAG 1.1 大模型的局限性 大模型的知识不是实时的,比如现在<藏海传& ...

  6. 好多分钟了解下java虚拟机--03

    垃圾回收 引用计数法和可达性分析 引用计数法 即记录对象的 reference count 若≠0则保留 a, b对象相互引用, 不可回收, 造成内存泄露 可达性分析(JVM主流使用) 从GC Roo ...

  7. 一次 .NET 性能优化之旅:将 GC 压力降低 99%

    字数 1128,阅读大约需 6 分钟 一次 .NET 性能优化之旅:将 GC 压力降低 99% 前言:问题的浮现 最近,我使用 ScottPlot 库开发一个频谱分析应用.应用的核心功能之一是实时显示 ...

  8. php 第三方网页应用授权登录扩展包 支持 微信、qq、微博、github gitee gitlaba 等第三方登录

    thirdparty_oauth 这是一个社会第三方登录扩展包 目前支持 微信.qq.微博.github gitee gitlaba 等第三方登录. [外链图片转存失败,源站可能有防盗链机制,建议将图 ...

  9. Cursor 实战万字经验分享,与 AI 编码的深度思考

    (本文属于面向全公司的一次 AI 编码经验分享) 零 ❀ 引 在使用 cursor 编程的过程中,我知道大家偶尔会有如下感受: 我只是单纯想和 cursor 聊天聊问题,为什么 cursor 莫名其妙 ...

  10. 一款开源免费、通用的 WPF 主题控件包

    前言 今天大姚给大家分享一款开源免费(MIT License).通用的 WPF 主题控件包:Rubyer WPF. WPF介绍 WPF是一个强大的桌面应用程序框架,用于构建具有丰富用户界面的 Wind ...