问题 C: To Fill or Not to Fill
#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的更多相关文章
- 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 ...
- 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 ...
- 【贪心】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 ...
- 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 ...
- PAT甲级1033. To Fill or Not to Fill
PAT甲级1033. To Fill or Not to Fill 题意: 有了高速公路,从杭州到任何其他城市开车很容易.但由于一辆汽车的坦克容量有限,我们不得不在不时地找到加油站.不同的加油站可能会 ...
- 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 ...
- 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题
题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- new 的实现原理
自己封装一个new <script> // 创建一个构造函数 function Father() { this.name = '小红'; this.eat = function () { ...
- linux下使用gdb对php源码调试
title: linux下使用gdb对php源码调试 date: 2018-02-11 17:59:08 tags: --- linux下使用gdb进行php调试 调试了一些php的漏洞,记录一下大概 ...
- Ant Design Vue Pro 项目实战-项目初始化(一)
写在前面 时间真快,转眼又是新的一年.随着前后端技术的不断更新迭代,尤其是前端,在目前前后端分离开发模式这样的一个大环境下,交互性.兼容性等传统的开发模式已经显得有些吃力.之前一直用的是react,随 ...
- SpringBoot图文教程5—SpringBoot 中使用Aop
有天上飞的概念,就要有落地的实现 概念+代码实现是本文的特点,教程将涵盖完整的图文教程,代码案例 文章结尾配套自测面试题,学完技术自我测试更扎实 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例 ...
- RFC笔记—Neighbor Discovery for IP version 6 (IPv6)
Router Solicitation Message Source Address An IP address assigned to the sending interface, or the u ...
- df du 文件空间管理 命令
df 可以查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力. du 可以查看文件及文件夹的大小. df:常用 df -h 以易读形式显示 磁盘空间 linux ...
- Vscode开发Python环境安装
VSCode 开发 Python 使用python,主要是做一些工具和爬虫的操作,语法简单,功能复杂,入手很快. 我们通过在 VSCode 中搜索 Python 插件,发现,开发 python 的话, ...
- [Redis-CentOS7]Redis安装(-)
系统环境 CentOS Linux release 7.7.1908 (Core) yum安装 yum install redis Loaded plugins: fastestmirror Load ...
- 杭电-------2098 分拆素数和(c语言写)
#include<stdio.h> #include<math.h> ] = { , }; ;//全局变量,用来标志此时已有多少个素数 int judge(int n) {// ...
- pip 自己的源 搭建
1 安装工具 pip install pip2pi 2 下载 所需要的包 pip2tgz /application/nginx/html/yum/python/ apscheduler (172 ...