博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT 1033 To Fill or Not to Fill[dp]
阅读量:4611 次
发布时间:2019-06-09

本文共 2195 字,大约阅读时间需要 7 分钟。

1033 To Fill or Not to Fill(25 分)

With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give different price. You are asked to carefully design the cheapest route to go.

Input Specification:

Each input file contains one test case. For each case, the first line contains 4 positive numbers: Cmax​​ (≤ 100), the maximum capacity of the tank; D (≤30000), the distance between Hangzhou and the destination city; Davg​​ (≤20), the average distance per unit gas that the car can run; and N (≤ 500), the total number of gas stations. Then N lines follow, each contains a pair of non-negative numbers: Pi​​, the unit gas price, and Di​​ (D), the distance between this station and Hangzhou, for i=1,,N. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the cheapest price in a line, accurate up to 2 decimal places. It is assumed that the tank is empty at the beginning. If it is impossible to reach the destination, print The maximum travel distance = X where X is the maximum possible distance the car can run, accurate up to 2 decimal places.

Sample Input 1:

50 1300 12 86.00 12507.00 6007.00 1507.10 07.20 2007.50 4007.30 10006.85 300

Sample Output 1:

749.17

Sample Input 2:

50 1300 12 27.10 07.00 600

Sample Output 2:

The maximum travel distance = 1200.00

 题目大意:第一行包含4个整数,Cmax即汽缸最大容量(<=100),D杭州到终点的距离(<=30000),Davg每单位汽油可以跑多少公里(<=20),N(<=500)加油站总数。

下面是N行,Pi表示当前加油站单位汽油价格,Di表示这个加油站距离杭州(起点)的距离。

求解出一种最省钱的方法从杭州到大目的地。

//那么先按从近到远的排个序,要加就得加满吗?

代码转自:https://www.cnblogs.com/chenxiwenruo/p/6735382.html

#include 
#include
#include
#include
#include
#define INF 0x3f3f3f3fusing namespace std;const int maxn=505;int capacity,dis,davg;int n;struct Gas{ double price; int dis;//到起点的距离。 bool operator<(const Gas tmp)const{
//重载运算符。 return dis
=gas[j].dis){ //若找到第一个比当前车站价格小的车站,就不继续往下找了 if(gas[j].price

 

//这个真的很厉害,要多复习! 

 

转载于:https://www.cnblogs.com/BlueBlueSea/p/9593954.html

你可能感兴趣的文章
[luogu4310] 绝世好题 (递推)
查看>>
[luogu3203 HNOI2010] 弹飞绵羊 (分块)
查看>>
mui搜索框 搜索点击事件
查看>>
超链接样式设置(去下划线)(转)
查看>>
2016012003+陈琦+散列函数的应用及其安全性
查看>>
Android 状态栏通知Notification、NotificationManager详解
查看>>
UIApplicationDelegate协议
查看>>
Jmeter测试dubbo接口填坑
查看>>
[zz]GDB调试精粹及使用实例
查看>>
数据库的创建和删除
查看>>
最简单的三层实例【插入据
查看>>
设计模式学习笔记——Prototype原型模式
查看>>
pom.xml里有红叉报错的解决办法
查看>>
Perl last和next的用法区别
查看>>
Selenium 管理 Cookies
查看>>
exceptionfunction[LeetCode]Permutations
查看>>
Linux(2)_常用命令2
查看>>
自定义分页
查看>>
[转]DELPHI——调试(1)
查看>>
JS秒数转成分秒时间格式
查看>>