PAT 甲级 1033 To Fill or Not to Fill
发布日期:2021-07-01 03:09:01 浏览次数:2 分类:技术文章

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

1033 To Fill or Not to Fill (25 point(s))

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: C​max​​ (≤ 100), the maximum capacity of the tank; D (≤30000), the distance between Hangzhou and the destination city; D​avg​​ (≤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: P​i​​, the unit gas price, and D​i​​ (≤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 = Xwhere 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

Experiential Summing-up

The significant point need to notice is Cmax,Darg,D and every station's distance are double float type. Or you will get wrong answer. As for the greedy algorithm, it did need profoundly understand. See the code for details. That's all~ 

(The purpose of using English to portray my solution is that to exercise the ability of my expression of English and accommodate PAT advanced level's style.We can make progress together by reading and comprehending it. Please forgive my basic grammar's and word's error. Of course, I would appreciated it if you can point out my grammar's and word's error in comment section.( •̀∀•́ ) Furthermore, Big Lao please don't laugh at me because I just a English beginner settle for CET6    _(:з」∠)_  )

Accepted Code

#include 
#include
#include
#include
using namespace std;const int maxn=510;const int INF=0x3fffffff;double Cmax,D,Darg;int n;struct station{ double price; double dis;}sta[maxn];bool cmp(station a,station b){ return a.dis
D) break; if(sta[i].dis<=curlen&&sta[i].dis+maxdis>=curlen) { int first=0,min=i; for(int j=i;j<=n;++j) { if(sta[j].dis<=curlen&&sta[j].dis+maxdis>=curlen) { if(sta[j].price

 

转载地址:https://meteorrain.blog.csdn.net/article/details/86608126 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:PAT 甲级 1034 Head of a Gang
下一篇:PAT 甲级 1032 Sharing

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月23日 18时07分56秒