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: C​max​​ (≤ 100), the maximum capacity of the tank; D (≤30000), the distance between Hangzhou and the destination city; D​avg​​ (≤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: P​i​​, the unit gas price, and D​i​​ (≤), 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 分)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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) ...

  4. 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 ...

  5. PAT (Basic Level) Practice (中文)1055 集体照 (25 分) 凌宸1642

    PAT (Basic Level) Practice (中文)1055 集体照 (25 分) 凌宸1642 题目描述: 拍集体照时队形很重要,这里对给定的 N 个人 K 排的队形设计排队规则如下: 每 ...

  6. 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 ...

  7. PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)

    简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  8. PAT (Advanced Level) 1097. Deduplication on a Linked List (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)

    简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

随机推荐

  1. [HTML辅助方法-Html.Raw()的简单应用]

    Html.Raw(); 当我们使用 文本编辑器,存入到数据库中的数据会带 html 标签,如果我们需要在前台显示存入时的相同样式,不输出为带有html标签的字符串 ,不通过富文本显示的话,可以通过ht ...

  2. java删除文件夹或者文件

    private static void deleteFile(File file) { if (file.exists()) { // 判断文件是否存在 if (file.isFile()) { // ...

  3. JAVA初级面试题,附个人理解答案

    一,面向对象的特征:1.抽象 包括数据抽象跟行为抽象,将对象共同的特征取出形成一个类2.继承 被继承类为基类/超类,继承类为子类/派生类3.封装 多次使用道德数据或方法,封装成类,方便多次重复调用4. ...

  4. 【flask】处理表单数据

     表单数据的处理涉及很多内容,除去表单提交不说,从获取数据到保存数据大致会经历以下步骤: 解析请求,获取表单数据. 对数据进行必要的转换,比如将勾选框的植转换为Python的布尔值. 验证数据是否符合 ...

  5. 创建的项目如果没有src/main/resources文件夹,如何解决?

    这是刚创建的一个maven项目,由此可以看见,项目并没有存放配置文件的src/main/resources文件夹? 解决方案: (1)选中项目,右键单击,如图所示选择:Build Path --> ...

  6. runoob_Java 序列化

    Java 序列化 Java 提供了一种对象序列化的机制,该机制中,一个对象可以被表示为一个字节序列,该字节序列包括该对象的数据.有关对象的类型的信息和存储在对象中数据的类型. 将序列化对象写入文件之后 ...

  7. centos7使用kubeadm安装kubernetes集群

    参考资料:官方文档 一.虚拟机安装 配置说明: windows下使用vbox,centos17.6 min版,kubernetes的版本是1.14.1, 安装如下三台机器: 192.168.56.15 ...

  8. GO——beego安装及新建项目(一)

    beego简介 Beego是一个快速开发Go应用的http框架,可用于快速开发Api.web及后端服务等各种应用,是一个RESTful框架. beego的架构 Beego由八个独立模块构建,是一个高度 ...

  9. Angular5 tslint错误:The selector of the component “XXXComponent” should be used as element

    错误描述 在项目中自己封装了一个 select 组件 @Component({ selector: '[app-choosen-select]', templateUrl: './selectcomm ...

  10. hbase 查看hfile文件

    emp表数据结构 hbase(main):098:0> scan 'emp' ROW COLUMN+CELL row1 column=mycf:depart, timestamp=1555846 ...