题目:

Language:
Expedition
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 31110 Accepted: 8559
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.
Source
USACO 2005 U S Open Gold

题意:一辆车需要经过L单位到达目的地,每单位路程耗1单位的油,一开始有p的油,途中有N个加油站,给出每个加油站距离终点的距离和可加油量,求能到达终点的最小加油次数

思路:用优先队列,模拟车走的过程,每次遇到加油站就把加油站的油量加入优先队列,如果走到某一个地方车里的油没了且队列中没有油可以加了,那就是走不到了,如果有油可以加,出队然后答案+1

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define pi acos(-1)
using namespace std;
struct node
{int d,l;
}a[10010];
int n,l,p,ans;
int cmp(node a,node b)
{return a.d>b.d;
}
int main()
{cin>>n;for (int i=1;i<=n;i++)scanf("%d%d",&a[i].d,&a[i].l);sort(a+1,a+1+n,cmp);cin>>l>>p;priority_queue<int> q;int k=1;while (1){if (l<=0){cout<<ans;return 0;}if (p==0 && !q.empty()){p+=q.top();q.pop();ans++;}if (p<0){cout<<-1;return 0;}l--;p--;if (l==a[k].d)q.push(a[k++].l);}return 0;
}

2019_GDUT_新生专题V算法优化 F. Expedition POJ 2431相关推荐

  1. 2019_GDUT_新生专题V算法优化 B. A Simple Problem with Integers POJ 3468

    来源 POJ3468 题目: You have N integers, A1, A2, - , AN. You need to deal with two kinds of operations. O ...

  2. 2019_GDUT_新生专题IV数论 G

    题目:美素数 题目链接:https://vjudge.net/contest/351853#problem/G 题目描述: 美素数:各位相加后,依然是素数. 在给出区间内找美素数的个数. 1.得出素数 ...

  3. 2019_GDUT_新生专题I选集——C

    题目:[POJ]1979 ----Red and Black 原题连接:http://poj.org/problem?id=1979 题目描述:给出一个图,其中有主人公(@),障碍物(#),可移动区域 ...

  4. 基于深度学习实现语义识别和问答判断模型及算法优化-制造业-CSDN公开课-专题视频课程...

    基于深度学习实现语义识别和问答判断模型及算法优化-制造业-1685人已学习 课程介绍         本次课程,邀请IBM研究院讲师就制造业语义识别及判断模型搭建.QA模型.词向量.句子量化.POWE ...

  5. python pso_利用python实现PSO算法优化二元函数

    python实现PSO算法优化二元函数,具体代码如下所示: import numpy as np import random import matplotlib.pyplot as plt from ...

  6. 【PID优化】基于matlab粒子群算法优化BP神经网络PID控制【含Matlab源码 2022期】

    ⛄一.粒子群算法优化BP神经网络PID控制简介 BP神经网络PID控制算法 传统PID控制器作为一种线性控制器,具备结构,容易实现的优点,其基本原理是将系统的实际输出值和期望输出值之间的偏差按照比例. ...

  7. 校园地图设计——任意两点间的算法优化流程与while搭配switch语句的bug解读

    建议大家看着篇文章之前,先把我的校园地图设计那篇文章了解一下,这篇文章是阐述程序设计中存留的优化问题 话不多说,先上代码 /输出任一两点间的最短路径与长度 void Dispath(int dist[ ...

  8. 时序预测 | python实现仿生算法优化LSTM时间序列预测(全网最全仿生算法)

    ** 时序预测 | python实现仿生算法优化LSTM时间序列预测(全网最全仿生算法) ** 多变量/单变量预测程序 多变量/单变量预测程序 多变量/单变量预测程序 A ABC-LSTM--人工蜂群 ...

  9. 【AI PC端算法优化】一,一步步优化RGB转灰度图算法

    欢迎关注AI PC端算法优化代码库:https://github.com/BBuf/Image-processing-algorithm-Speed . 0. 资源获取 公众号输入 高性能计算 关键词 ...

最新文章

  1. PDF与doc格式互换
  2. ffmpeg时间基种类及转换
  3. Css标题中图片居中,图片居中:任意图片在div里的上下垂直都居中!
  4. 【渝粤题库】国家开放大学2021春1078复变函数题目
  5. oracle数据库触发器删除不,Oracle之后删除触发器
  6. OpenCV傅立叶变换
  7. 给你1分钟,回答下RabbitMQ如何保证消息不丢?
  8. Xcode7.0.1:升级Xcode7上传AppStore失败问题
  9. matlab与水库调度,蛙跳算法优化水库调度,全局迭代中最优解未更新
  10. 如何才能通过设置将excel单元格内的14位数字转换为日期格式
  11. 计算机网络综合实践任务书,计算机网络综合实任务书2012-11.doc
  12. 华为鸿蒙专属文件后缀,华为鸿蒙——上传第三方APP【原理公布】
  13. cad2019菜单栏怎么调出来_cad怎样调出菜单栏(cad2016工具栏怎么调出来)
  14. 批处理文件rd \s\q **是什么意思?
  15. 用来判断当前python语句在分支结构中是_【单选题】哪个选项是用来判断当前 Python 语句在分支结构中?...
  16. 红豆 2022年3月16日
  17. C#入门学习笔记(基于刘铁锰老师C#入门2014教学视频)【2】
  18. Exception in thread main java.sql.SQLException: Access denied for user ''@'localhost' (using passw
  19. Emmet 食用指北
  20. 【技巧】ApiPost生成word格式的接口文档,接口文档合并操作

热门文章

  1. sws_scale函数像素数据格式的转换yuv转rgba
  2. GN_2_使用GN编译自己写的程序
  3. TP-LINK无线路由器屏蔽恶意网站方法
  4. 关于风险和收益的想法
  5. 07 Python数据类型详解
  6. SEO可以分为5个层次
  7. 国内最新最全面IP数据库
  8. 上海居住证 居转户条件
  9. 什么是BACKHAUL
  10. DC888 : 数据流分析