#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath> using namespace std; struct station {
double per_price;
double distance;
}; bool cmp(const station &s1, const station &s2) {
return s1.distance < s2.distance;
} int main() { double tank_c, distance, unit_d;
int n;
while (scanf(" %lf%lf%lf%d", &tank_c, &distance, &unit_d, &n) != EOF) { double cost = 0;
double current_dis = 0;
double current_tank = 0;
double MAX_LEN = tank_c * unit_d; station stations[n + 1];
for (int i = 0; i < n; ++i) {
scanf(" %lf %lf", &stations[i].per_price, &stations[i].distance);
} station temp = {0, distance};
stations[n++] = temp; sort(stations, stations + n, cmp); if (stations[0].distance != 0) {
printf("The maximum travel distance = 0.00\n");
break;
} //当前站点
int k = 0;
while (current_dis < distance) {
int nextK = k;
int min_k = k;
double min_price = 999;
double max_distance = MAX_LEN + current_dis; if (stations[k + 1].distance - current_dis > MAX_LEN) break; bool flag = false;
for (int i = k + 1; i < n && stations[i].distance <= max_distance; ++i) {
if (stations[i].per_price < stations[k].per_price) {
flag = true;
nextK = i;
break;
}
if (stations[i].per_price < min_price) {
min_price = stations[i].per_price;
min_k = i;
} } double left = current_tank * unit_d;
//
if (flag) { cost += ((stations[nextK].distance -stations[k].distance - left) / unit_d) * stations[k].per_price;
k = nextK;
current_dis = stations[nextK].distance;
current_tank = 0;
} else {
//加满
cost += ((MAX_LEN -left) / unit_d) * stations[k].per_price; current_dis = stations[min_k].distance;
current_tank = tank_c - (stations[min_k].distance - stations[k].distance)/unit_d;
k = min_k;
} } if (current_dis == distance)
printf("%.2lf\n", cost);
else
printf("The maximum travel distance = %.2lf\n", stations[k].distance + MAX_LEN); }
return 0;
}

问题 C: To Fill or Not to Fill的更多相关文章

  1. 1033. To Fill or Not to Fill (25)

     题目链接:http://www.patest.cn/contests/pat-a-practise/1033 题目: 1033. To Fill or Not to Fill (25) 时间限制 1 ...

  2. 1033 To Fill or Not to Fill

    PAT A 1033 To Fill or Not to Fill With highways available, driving a car from Hangzhou to any other ...

  3. 【贪心】PAT 1033. To Fill or Not to Fill (25)

    1033. To Fill or Not to Fill (25) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 ZHANG, Gu ...

  4. 1033 To Fill or Not to Fill (25 分)

    1033 To Fill or Not to Fill (25 分) With highways available, driving a car from Hangzhou to any other ...

  5. PAT甲级1033. To Fill or Not to Fill

    PAT甲级1033. To Fill or Not to Fill 题意: 有了高速公路,从杭州到任何其他城市开车很容易.但由于一辆汽车的坦克容量有限,我们不得不在不时地找到加油站.不同的加油站可能会 ...

  6. PAT 1033 To Fill or Not to Fill[dp]

    1033 To Fill or Not to Fill(25 分) With highways available, driving a car from Hangzhou to any other ...

  7. 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题

    题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...

  8. pat1033. To Fill or Not to Fill (25)

    1033. To Fill or Not to Fill (25) 时间限制 10 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 ZHANG, Gu ...

  9. PAT 甲级 1033 To Fill or Not to Fill (25 分)(贪心,误以为动态规划,忽视了油量问题)*

    1033 To Fill or Not to Fill (25 分)   With highways available, driving a car from Hangzhou to any oth ...

  10. PAT_A1033#To Fill or Not to Fill

    Source: PAT A1033 To Fill or Not to Fill (25 分) Description: With highways available, driving a car ...

随机推荐

  1. linux下使用gdb对php源码调试

    title: linux下使用gdb对php源码调试 date: 2018-02-11 17:59:08 tags: --- linux下使用gdb进行php调试 调试了一些php的漏洞,记录一下大概 ...

  2. 【转】JAVA BIO与NIO、AIO的区别

    Java中IO的模型分为三种,同步阻塞的BIO.同步非阻塞的NIO.异步非阻塞的AIO. BIO[同步阻塞] 在JDK1.4出来之前,我们建立网络连接的时候采用BIO模式,需要先在服务端启动一个Ser ...

  3. 基于原生的 html css js php ajax做的一个 web登录和注册系统

    完整代码下载: 百度网盘地址 https://pan.baidu.com/s/1D1gqHSyjgfoOtYCZm7ofJg 提取码 :nf0b 永久有效 注意: 1 如果要正常运行此示例, 本地需要 ...

  4. 向C++之父Bjarne Stroustrup致敬

    2013-04-25 21:30 (分类:社会人生) 非常好的文章 C ++ 的 背 影                                     ——C++之父Bjarne Strou ...

  5. JavaScript——event事件详解

    1.事件对象 Event 对象代表事件的状态,比如事件在其中发生的元素.键盘按键的状态.鼠标的位置.鼠标按钮的状态. 什么时候会产生Event 对象呢? 例如: 当用户单击某个元素的时候,我们给这个元 ...

  6. 【转】Redis内部数据结构详解——ziplist

    本文是<Redis内部数据结构详解>系列的第四篇.在本文中,我们首先介绍一个新的Redis内部数据结构--ziplist,然后在文章后半部分我们会讨论一下在robj, dict和zipli ...

  7. WinFrom 在Devexpress里用GridControl和DataNavigtor进行分页

    1,分页嘛先要有个SQL 程序才能写下去 先提供下SQL的思路,对于分页的SQL我之前帖子有介绍,就不一一介绍了 select top pageSize * --显示数量 from (select r ...

  8. 浏览器中常见的html语义化标签

    html标签默认在浏览器中展示的样式,html标签的用途:语义化(明白每个标签的用途,在什么情况下使用此标签合理);标签语义化好处:1.更容易被搜索引擎收录2.更容易让屏幕阅读器读出网页内容. 网页上 ...

  9. 「Flink」使用Managed Keyed State实现计数窗口功能

    先上代码: public class WordCountKeyedState { public static void main(String[] args) throws Exception { S ...

  10. 软链接和硬链接——Linux中的文件共享

    硬链接(Hard Link)和软链接也称为符号链接(Symbolic Link)的目的是为了解决文件的共享使用问题.要阐明其原理,必须先理解Linux的文件存储方式. 索引结点 Linux是一个UNI ...