#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. Java开发最佳实践(一) ——《Java开发手册》之"编程规约"

    Java开发手册版本更新说明 专有名词解释 一. 编程规约 (一) 命名风格 (二) 常量定义 (三) 代码格式 (四) OOP 规约 (五) 集合处理 (六) 并发处理 (七) 控制语句 (八) 注 ...

  2. 怎么用wait、notify巧妙的设计一个Future模式?

    我们知道多线程可以实现同时执行多个任务(只是看起来是同时,其实是CPU的时间片切换特别快我们没感觉而已). 现在假设一个做饭的场景,你没有厨具也没有食材.你可以去网上买一个厨具,但是这段时间,你不需要 ...

  3. 单元测试-xUnit总结

    xUnit总结 什么是xUnit xUnit.net是针对.NET Framework的免费,开源,以社区为中心的单元测试工具. 自动化测试的优点 可以频繁的进行测试 可以在任何时间进行测试,也可以按 ...

  4. C语言基础五 数组的应用

    .根据用户输入的10人成绩并将其保存到数组中,求最高成绩,最低成绩和平均成绩 int scoure[10];//存储10个数据的数组 int i; int sum;//总成绩 int max,min, ...

  5. Linux安装Redis,在测试阶段即make test出现“You need tcl 8.5 or newer in order to run the Redis test”问题解决方案

    Linux安装Redis,在测试阶段即make test出现"You need tcl 8.5 or newer in order to run the Redis test"问题 ...

  6. C++泛化单链表

    泛型单链表 单链表将每个数据分为节点,每个节点存储数据和指向下一个节点的指针.这样数据就不用在内存中使用连续的存储空间,有更大的灵活性. 这里将单链表分为节点类(Node)和链表类(singleLin ...

  7. StackExchange.Redis 之 Set集合 类型示例

    话不多说直接上代码: // set添加单个元素 stopwatch.Start(); "); stopwatch.Stop(); Console.WriteLine("set添加单 ...

  8. Javascript 基础学习(五)js 的运算符

    通过运算符可以对一个或多个值进行运算,并且一定有运算结果返回 算数运算符 ​ 算数运算符包括相加(+).相减(-).相乘(*).相除(/).取模(%).任何值与字符串相加都会转换为字符串,做的是字符串 ...

  9. mysql必知必会--用正则表达式 进行搜索

    正则表达式介绍 前两章中的过滤例子允许用匹配.比较和通配操作符寻找数据.对 于基本的过滤(或者甚至是某些不那么基本的过滤),这样就足够了.但 随着过滤条件的复杂性的增加, WHERE 子句本身的复杂性 ...

  10. 使用Xcode7非美刀购买开发者帐号,非越狱安装IOS ipa

    做苹果开发,需要至少99美刀注册开发者帐号,这样写出来的程序才可以在真机上运行调试,才可以发布到app store,现在xcode7之后苹果有了调整,除了发布到app store还是需要美刀帐号,其它 ...