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> ...
随机推荐
- leetcode-easy-others-20 Valid Parentheses
mycode 95.76% class Solution(object): def isValid(self, s): """ :type s: str :rtype ...
- leetcode-easy-design-155 Min Stack
mycode 21.48% class MinStack(object): def __init__(self): """ initialize your data ...
- 乌班图docker版本18.04升级到19.03
# 关闭docker sudo systemctl stop docker # 卸载旧版本: sudo apt-get purge docker-ce # 安装新版本 sudo apt update ...
- Android 获取视频照片与刷新媒体库
1.获取本地所有视频 public void getLoadMedia() { Cursor cursor = UILApplication.instance.getApplicationContex ...
- SpringBoot 启动流程
SpringBoot 启动流程 加载 resources/META-INF/spring.factories 中配置的 ApplicationContextInitializer 和 Applicat ...
- Android6.0运行时权限的处理Demo
MainActivity.java package com.loaderman.permissionsdemo; import android.Manifest; import android.con ...
- 阶段3 2.Spring_08.面向切面编程 AOP_1 AOP的概念
- PHP加速器eAccelerator安装
程序说明 eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对 服务器的开销几乎为零. 它还有对脚本起优化作用,以加 ...
- freebsd 隐藏ssh版本号
方案一: vi /etc/ssh/sshd_config VersionAddendum 为空或者no或者别的信息 /etc/rc.d/sshd restart 方案二: https://kram.n ...
- JSON中文处理类实例
$array = array( 'Name'=>'络恩', 'Age'=>24); $post=my_json_encode($array); // 这个函数是判断版本,如果是搞版本的则直 ...