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> ...
随机推荐
- NavisWorks连接外部数据库,为模型附加属性
可以直接从Navisworks 文件连接到外部数据库,并在场景中的对象与数据库表中的字段之间创建链接以引入额外特性. 1.连接mdb数据库 新建数据连接 单击“新建”按钮,新建数据连接,输入一个名称, ...
- leetcode 714. 买卖股票的最佳时机含手续费
继承leetcode123以及leetcode309的思路,,但应该也可以写成leetcode 152. 乘积最大子序列的形式 class Solution { public: int maxProf ...
- linux_Ubuntu相对路径和绝对路径
绝对路径 从/目录开始描述的路径为绝对路径,如: cd /home ls /usr 相对路径 从当前位置开始描述的路径为相对路径,如: cd ../../ ls abc/def .和.. 每个目录下都 ...
- iOS 图表工具charts之BarChartView
关于charts的系列视图介绍传送门: iOS 图表工具charts介绍 iOS 图表工具charts之LineChartView iOS 图表工具charts之BarChartView iOS 图表 ...
- apache禁止php解析--安全
#禁止解析php <Directory "/data/www/data/"> php_admin_flag engine off <filesmatch &quo ...
- 简单方法让input date支持placeholder(包含ios手机端方法)
<input class="baixin-quan-info-box-time" type="text" onfocus="(this.type ...
- mxml 嵌入as代码出错,缺少 CDATA
如果<mx:Script> 中有大于小于符号,代码必须包含在<![CDATA[ 之中,否则会报错
- Kibana 5.5.2 安装包下载 (各种历史版本下载)
背景说明 最近项目中在使用 5.5.2 版本的 Elasticsearch 作为数据库,使用的是以前的老版本. 用到 Elasticsearch ,难免要和其相关基本操作命令打交道.选择一款顺手的工 ...
- java:Hibernate框架4(延迟加载(lazy),抓取(fetch),一级缓存,get,load,list,iterate,clear,evict,flush,二级缓存,注解,乐观锁和悲观锁,两者的比较)
1.延时加载和抓取: hibernate.cfg.xml: <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-co ...
- 【内部】Fiddler设置代理请求的方式
1.2 打开Fiiddler,设置如图步骤: 3.添加规则: 4.这里选择第三个选项: 5.选中^开始,空格结束的如图内容.复制你要代理的地址.如:http://wap.cmread.com/nap/ ...