PAT Advanced 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 (≤), the distance between this station and Hangzhou, for ,. 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 8
6.00 1250
7.00 600
7.00 150
7.10 0
7.20 200
7.50 400
7.30 1000
6.85 300
Sample Output 1:
749.17
Sample Input 2:
50 1300 12 2
7.10 0
7.00 600
Sample Output 2:
The maximum travel distance = 1200.00
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int a,b,sum=,tmp;
vector<int> vec1,vec2;
cin>>a;
while(a--){
scanf("%d",&tmp);
vec1.push_back(tmp);
}
cin>>b;
while(b--){
scanf("%d",&tmp);
vec2.push_back(tmp);
}
sort(vec1.begin(),vec1.end(),greater<int>());
sort(vec2.begin(),vec2.end(),greater<int>());
int i=;int j=;
while(vec1[i]>&&vec2[j]>){
sum+=(vec1[i]*vec2[j]);
i++;
j++;
if(i>vec1.size()-||j>vec2.size()-) break;
//尽量少用erase,擦除线性表是需要一个复杂度的
}
i=vec1.size()-;j=vec2.size()-;
while(vec1[i]<&&vec2[j]<){
sum+=(vec1[i]*vec2[j]);
i--;
j--;
if(i<||j<) break;
}
cout<<sum;
system("pause");
return ;
}
PAT Advanced 1033 To Fill or Not to Fill (25 分)的更多相关文章
- PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642
PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...
- PAT (Advanced Level) Practice 1055 The World's Richest (25 分) (结构体排序)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642
PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...
- PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642
PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...
- PAT (Basic Level) Practice (中文)1055 集体照 (25 分) 凌宸1642
PAT (Basic Level) Practice (中文)1055 集体照 (25 分) 凌宸1642 题目描述: 拍集体照时队形很重要,这里对给定的 N 个人 K 排的队形设计排队规则如下: 每 ...
- PAT Advanced 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 tan ...
- PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)
简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1097. Deduplication on a Linked List (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)
简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- springboot之RocketMq实现
环境:win10 1.下载安装包 http://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.4.0/rocketmq-all-4.4.0-bin-re ...
- BurpSuite(一)工具介绍
, 本章目标: 1. 安装并配置好Burpsuite 2. 了解其各个模块功能 Burpsuite介绍 Burp Suite 是用于攻击web应用程序的集成平台.它包含了许多工具,并为这些工具设计了许 ...
- linux 下的快捷键操作
概述 今天发现自己码代码的效率有点低,所以查找了一下 linux 常用的快捷键操作,记录下来,供以后开发时参考,相信对其他人也有用. linux 终端常用快捷键 tab:补全命令 Ctrl + u:剪 ...
- Python线程和协程
写在前面 好好学习 天天向上 一.线程 1.关于线程的补充 线程:就是一条流水线的执行过程,一条流水线必须属于一个车间: 那这个车间的运行过程就是一个进程: 即一个进程内,至少有一个线程: 进程是一个 ...
- enumerable 可枚举 属性
一个对象的可枚举属性会在for...in中被访问到 (或是类似的迭代方法, Object.keys() 如果一个属性不是可枚举的,循环会忽略这个属性 var obj = { key: 'val' }; ...
- 阶段3 2.Spring_06.Spring的新注解_6 Qualifier注解的另一种用法
复制上面的数据源到下面改改名字 现在就是有两个数据源 创建一个eesy02的数据库 找到sql语句再创建Account表 现在就相当于有连个库一个eesy一个是eesy02这连个库. account里 ...
- DVWA、 DSVM 环境搭建简述
DVWA(http://www.dvwa.co.uk/)是一个本地的漏洞演示环境基于PHP和Mysql . 另外还有基于Python的DSVM部署起来也十分简单.(https://github.com ...
- Spring MVC 中使用AOP 进行统一日志管理--XML配置实现
1.介绍 上一篇博客写了使用AOP进行统一日志管理的注解版实现,今天写一下使用XML配置实现版本,与上篇不同的是上次我们记录的Controller层日志,这次我们记录的是Service层的日志.使用的 ...
- 修改python pip3镜像源
方法一: pip3 install 包名 -i 镜像源url 主要的镜像源: pip3 install tornado -i https://pypi.douban.com/simple/ pip ...
- MySQL5.6解压版服务无法启动—系统错误1067
记录一下今天被坑了一下午的BUG 就从半个月前说起吧 当时....................................................................... ...