PTA-甲级 1033 To Fill or Not to Fill(测试点2)

SAP UI5 百科全书的目录 笔者 12 年 SAP UI5 开发岁月中写下的 595 篇 SAP UI5 学习笔记,全部收录到《SAP UI5 百科全书》专栏中去,目录如下。请大家按照自己的学习需要,根据关键字搜索到对应的文章,然后进行学习。 阅读详情

PTA-甲级 1033 To Fill or Not to Fill(测试点2)

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 (≤D), the distance between this station and Hangzhou, for i=1,⋯,N. 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

知识点: 贪心算法

算法:

if 最近一站距离<cmax*davg
	去不了终点了;
	break;
else 在能到达范围内,
	if 存在更低油价
		选择最近的油价更低的作为下一站;
	else if 能到终点了
		去终点;
	else 去能到达的最远的一站;

注意点:

1.不要直接用测试里的12、600的数据…这是输入进来的不是自带的(修正后测试点1、6过了)

2.测试点2是第一个站不在原点的情况,直接输出 The maximum travel distance = 0.00

3.测试点4错误可能是到终点的情况出现了问题(猜测)

代码:

#include<iostream>
#include<algorithm>
using namespace std;
int cmax,d,davg,n;
double total;
struct stu{
	int dis;
	double pri;
} sta[505];
bool comp(stu a, stu b){
	return a.dis<b.dis;
}
int main(){
	total=0.0;
	double cont=0.0;
	double distance=0.0;
	bool end=false;
	cin>>cmax>>d>>davg>>n;
	for(int i=0; i<n; i++){
		cin>>sta[i].pri>>sta[i].dis;
	}
	sta[n].dis=d;
	sta[n].pri=0;
	sort(sta, sta+n, comp);
	for(int i=0; i<n; i++){
		if(sta[i+1].dis-sta[i].dis>cmax*davg){
			distance+=cmax*davg;
			break;
		}
		for(int j=i+1; j<=n; j++){
			if(sta[j].dis-sta[i].dis>cmax*davg){
				total+=sta[i].pri*(cmax-cont); 	// 加满 
				cont=(cmax-(sta[j-1].dis-sta[i].dis)*1.00/davg)*1.00; 	// 去完下一站剩的油 
				i=j-2; 	//下一站
				distance=sta[j-1].dis; 
				break;
			}
			else if(j==n){
				total+=sta[i].pri*(sta[j].dis-sta[i].dis-cont*davg)/davg;
				cont=0; 	// 到终点油用完 
				end=true; 	// 到终点了 
				distance=d; 
				break;
			}
			else if(sta[j].pri<sta[i].pri){
				total+=sta[i].pri*(sta[j].dis-sta[i].dis-cont*davg)/davg;
				cont=0; 	//到一站油刚好用完 
				i=j-1;	// 下一站 
				distance=sta[j].dis; 
				break;
			}
		}
		if(end){
			break;
		}
	}
	if(sta[0].dis!=0){
		printf("The maximum travel distance = 0.00\n");
	}
	else if(end){
		printf("%.2f\n", total);
	}
	else{
		printf("The maximum travel distance = %.2f\n", distance);
	}
}
计算机视觉教程2-3:图解双线性插值算法&最近邻插值算法 提出此算法的背景是基于图片的缩放,在图片缩放的过程中,实质上就是将原图像像素矩阵像素值,填到目标图像像素矩阵中,目标图像像素矩阵可能比原图像像素矩阵大(图片放大),也可能小(图片缩小)。我们假设图片的宽(WidthWidthWidth)和高(HeightHeightHeight)是按同比例缩放的,那么 srcXsrcWidth=dstXdstWidth\frac{srcX}{srcWidth}= \frac{dstX}{dstWidth}srcWidthsrcX​=dstWidthdstX​ ... 阅读详情

相关推荐

电子结构设计(EMD)十年知识总结

客官,你的面相是做结构设计的奇才~1. 材料选择【一出手的0.1s就败了】2. 钣金件设计【折来折去有啥难】3. 塑胶件设计【看着好复杂】4. 型材件设计【凭啥不让我设计】5. 电子结构(PCBA)设计【静电肿么要我背锅】6. 包装设计【要的就是金玉其外,败絮其中】7. 外观(工业)设计【好不好看,谁说了算】8. 标签设计【】9. 标准件选择【一个螺丝难倒英雄汉/提起螺丝,英雄气短】10. 计算仿...

wfeng86的博客 1569

PAT甲级 1033 To Fill or Not to Fill (测试点2、4)

PAT甲级1033题

blueblue0808的博客 942

海思Hi3559A/CV100 DDR4参数配置经验分享

海思Hi3559A/CV100 DDR4参数配置方法 Hi3559AV100 DDR4 驱动配置说明 1.1 Hi3559AV100 DDR4 CLK/AC 驱动配置方法 寄存器地址 DDR PHY0:0x1206d0bc DDR PHY1:0x1206f0bc 寄存器描述 − Bit[5:3]:CLK 驱动 − Bit[14:12]:2T 驱动 − Bit[20:18]:1T 驱动 驱动大小定义 − 000:Disable − 001:240ohm − 010: 120ohm − 011:80ohm −

WeChat_zhanggong345的博客 2879

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 other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the ...

宝付支的博客 392

QGIS|如何将WGS84转换为CGCS 2000坐标系?

QGIS 3中如何将WGS84转换为国家2000大地坐标系? 今天来回答一位朋友在后台留言提出的问题:怎么将WGS84坐标转换为国家2000大地坐标系。 01工程坐标系 从地图窗口右下角的状态栏可以看到当前地图窗口的坐标系,即工程坐标系(Project CRS)。当前地图可以由多个图层组成,各种来源数据的坐标参照系(Layer CRS)并不一定相同,QGIS在绘制图层之前将根据工程坐标系进行动态坐标转换,然后显示在地图画布中。 因此,在处理空间数据的过程中,一定要特别注意...

QGISClass的博客 1万+

[Adaptive Autosar]深入理解--Time Synchronization

目录 1.TS典型应用场景 2.CP和AP时间同步对比 3.时间同步基础知识 4.TBR部分参数说明 5. TS功能说明 5.1 基本说明 5.2 时间纠正计算说明 5.3 时间验证 Time Synchronization 时间同步,后面简称TS 1.TS典型应用场景 时间同步,典型应用就是在自动驾驶领域,自动驾驶领域涉及到各个传感器的数据采集,如IMU采集当前车身姿态和运动信息,毫米波雷达-超声波雷达-环视摄像头-前视摄像头...等等传感器捕获的数据,在算法中需要精确知道每个数.

AgingMoon的博客 3997

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

weixin_30371469的博客 521

从FedAvg到实战:手把手教你用PyTorch复现联邦学习经典论文实验(MNIST/CIFAR-10)

本文详细介绍了如何使用PyTorch复现联邦学习经典算法FedAvg在MNIST和CIFAR-10数据集上的实验。从环境搭建、数据非IID划分到模型实现和参数聚合,手把手教你掌握联邦学习的核心技术与实战技巧,帮助开发者和研究人员快速实现隐私保护的分布式机器学习方案。

weixin_29053695的博客 253

PAT-AL 1033. To Fill or Not to Fill

1、知识点:贪心 2、思路:先将站按照距离从小到大排序。假设我有N个桶,第i号桶装第i站的汽油(i从0开始),第0站加满,到第i站时,选择从第i-1站到达此站最便宜的汽油(如果最便宜的不够用,选择次便宜的),然后将N个桶中所有比此站更贵的汽油原价卖出(说明之前买的多了,够用就好),然后加此站的油至加满(不管是不是比之前或后面的更贵,因为不加满怕到不了下个站)。最后到达终点时将所有剩下的油原价卖出即

EverydayIsLife的博客 438

AI测试:手把手教你用AI创建流程图「喂饭教程」

本文介绍了如何利用next-ai-draw-io开源项目,通过AI快速生成专业流程图,提升测试工作效率。该工具支持自然语言交互,兼容多种AI模型(如OpenAI、Claude等),并集成draw.io图表引擎,实现实时编辑。

blues_C的博客 759

Sigrity System SI SerialLink模式进行SFP+协议仿真分析-PCB操作指导

Random(Rj):随机抖动,该抖动用高斯概率分布来描述,通常是由热噪声和其它随机噪声引起的,默认为1%UI RMS(平均值),即和标准值的偏差为1%UI。Random(Rj):随机抖动,该抖动用高斯概率分布来描述,通常是由热噪声和其它随机噪声引起的,默认为1%UI RMS(平均值),即和标准值的偏差为1%UI。Random(Rj):随机噪声,是由信号电压的随机波动引起的,默认为1mv RMS(平均值),即和标准值的偏差为1mv。

weixin_54787054的博客 508

PAT甲级 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. Dif

changeforeve的博客 207

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

PAT 乙级-1033(测试点2)

测试点2:可能没有坏键,此时输入的第一行为空格,第二行为应该输入的文字,使用getline可以解决问题 #include<iostream> #include<cctype> using namespace std; int main() { string broken, ori; getline(cin, broken); getline(cin, ori); int flag = 0; if(broken.find('+') != string::npos) .

学习笔记,不喜勿喷! 280

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

PAT甲级2014秋季全解

PAT甲级2014秋季1. Broken Keyboard2. Perfect Sequence3. Tree Traversals Again4. All Roads Lead to Rome 1. Broken Keyboard On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not a

all23333333的博客 387

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

python-PAT甲级题解-1005

Given a non-negative integerN, your task is to compute the sum of all the digits ofN, and output every digit of the sum in English. Input Specification: Each input file contains one test case. Each case occupies one line which contains anN(≤10100). ...

m0_48118006的博客 1234

PAT甲级 2019年冬季 题解

题目1:7-1 Good in C (20分) When your interviewer asks you to write “Hello World” using C, can you do as the following figure shows? Input Specification: Each input file contains one test case. For each case, the first part gives the 26 capital English letters

我是没有梦想的小白 935

2021年秋季PAT甲级考试满分题解

7-1 Arrays and Linked Lists (20 分) Let’s design a data structure AAA that combines arrays and linked lists as the following: At the very beginning, an integer array A0A_0A0​ of length L0L_0L0​ is initialized for the user. When the user tries to access the

weixin_44589651的博客 1663

《算法笔记》3.1小节——入门模拟 问题 E: Shortest Distance (20)

题目描述 The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits. 输入 Each input file contains one test ca...

hwyu_95的博客 281

1075 PAT Judge

题目来源:PAT (Advanced Level) Practice The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT. Input Specification: Each input file contains one test case

weixin_51032998的博客 242

2021-11-04 PAT(6) 从简单题过渡到中等题

最近没做PAT了,有些忙,打算一个月激情冲刺PAT,目前就是偶尔做题。 1094 The Largest Generation (25 分) A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest po

Yiyan__的博客 749

【PAT刷题甲级】1075.PAT Judge

1075 PAT Judge (25 分) The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT. Input Specification Each input file contains one test case. For each case,

C_greenbird的博客 430

PAT - A1043 Is It a Binary Search Tree (25 分)

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right s...

DedicateToAI的博客 258

PAT(Advanced)甲级---1114 Family Property (25 分)【DFS,并查集】

This time, you are supposed to help us collect the data for family-owned property. Given each person's family members, and the estate(房产)info under his/her own name, we need to know the size of each f...

啸天的博客 365

1028. List Sorting (25)

 Excel can sort records according to any column. Now you are supposed to imitate this function. Input Each input file contains one test case. For each case, the first line contains two integers N

小卢卡斯的专栏 526

python-PAT甲级题解-1001

Calculatea+band output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input Specification: Each input file contains one test case. Each case contains a pair o..

m0_48118006的博客 310

【PAT甲级】1164 Good in C (20 分)

PAT甲级1164题解

小染的学习笔记 749
上一篇: PTA甲级-1057 Stack (超时)
下一篇: PTA-甲级 1094 The Largest Generation 深度优先
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值