PAT 甲级 1033 To Fill or Not to Fill(25 分)

PAT甲级真题 1033 To Fill or Not to Fill (25分) C++实现(贪心法) 题目 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. Differen... 阅读详情

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: 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​​ (≤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 = Xwhere 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 <algorithm>
#include <vector>
using namespace std;
const int inf = 99999999;
struct station {
    double price, dis;
};
bool cmp1(station a, station b) {
    return a.dis < b.dis;
}
int main() {
//	freopen("C:\\1.txt", "r", stdin);
    double cmax, d, davg;
    int n;
    scanf("%lf%lf%lf%d", &cmax, &d, &davg, &n);
    vector<station> sta(n + 1);
    sta[0] = {0.0, d};
    for(int i = 1; i <= n; i++)
        scanf("%lf%lf", &sta[i].price, &sta[i].dis);
    sort(sta.begin(), sta.end(), cmp1);
    double nowdis = 0.0, maxdis = 0.0, nowprice = 0.0, totalPrice = 0.0, leftdis = 0.0;
    // 现在所在加油站距离起始点的距离,最大可到达距离,现在所在加油站的油价,总价,剩余油量可以行驶的路程 
    if(sta[0].dis != 0) { // 出发点无加油站 
        printf("The maximum travel distance = 0.00");
        return 0;
    } else {
        nowprice = sta[0].price;
    }
    while(nowdis < d) {
        maxdis = nowdis + cmax * davg;
        double minPriceDis = 0, minPrice = inf;
        // 最低可到达距离, 最低价格 
        int flag = 0;
        for(int i = 1; i <= n && sta[i].dis <= maxdis; i++) {
            if(sta[i].dis <= nowdis) continue;
            if(sta[i].price < nowprice) { // 找到比起始点油价低的第一个站点 
                totalPrice += (sta[i].dis - nowdis - leftdis) * nowprice / davg;
                leftdis = 0.0;
                nowprice = sta[i].price;
                nowdis = sta[i].dis;
                flag = 1;
                break;
            }
            if(sta[i].price < minPrice) {  // 寻找起始点可达范围内油价最低的加油站 
                minPrice = sta[i].price;
                minPriceDis = sta[i].dis;
            }
        }
        if(flag == 0 && minPrice != inf) { // 如果可到达范围内油价都比起始点高,在起始站点加满油 
            totalPrice += (nowprice * (cmax - leftdis / davg));
            leftdis = cmax * davg - (minPriceDis - nowdis);
            nowprice = minPrice;
            nowdis = minPriceDis;     
        }
        if(flag == 0 && minPrice == inf) { // 在可到达范围内,无加油站 
            nowdis += cmax * davg;
            printf("The maximum travel distance = %.2f", nowdis);
            return 0;
        }
    }
    printf("%.2f", totalPrice);
    return 0;
}

 

【深度学习新浪潮】气候预测模型的研发进展一览(2025年版) 模型类型核心优势适用场景不足ARIMA(统计模型)简单高效、可解释性强短期单变量预测非线性、长时依赖建模差随机森林(机器学习)多特征融合、抗噪声中短期多因素预测空间相关性、时序趋势捕捉弱LSTM(深度学习)长时依赖建模、端到端中长期时序预测物理一致性差、数据需求量大物理知情AI物理规律约束、高可靠性极端天气、长期气候变化模型复杂、计算成本高。 阅读详情

相关推荐

TSMC 40nm LP工艺下,新手画版图最容易踩的5个坑(附Cadence避坑指南)

本文详细解析了TSMC 40nm LP工艺下版图设计的5个常见陷阱,包括MOS管尺寸转换、DNW隔离、Guard Ring设计、金属布线和DRC检查。通过Cadence实战技巧和设计规则优化,帮助新手工程师规避典型错误,提升版图设计效率和质量。

weixin_26800111的博客 458

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

PAT甲级1033题

blueblue0808的博客 942

手把手教你用T630芯片开发USB3.0数据采集卡(含FPGA对接避坑指南)

本文详细介绍了如何使用国产T630芯片开发USB3.0数据采集卡,包括FPGA对接的避坑指南。T630作为国产替代方案,相比传统CYUSB3014芯片,具有更高的传输带宽(实测410MB/s)和更完善的开发支持。文章从硬件设计、固件开发到上位机调试,提供了全流程的技术细节和优化技巧,助力开发者快速实现工业级数据采集系统。

weixin_42531163的博客 621

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

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 g

study_cs的博客 705

ANSYS拓扑优化基础实例

唐深51CAE 2018/6/10 拓扑优化在工程设计中,常用于机械结构概念设计和轻量化设计,ANSYS通用有限元分析软件提供了强大的拓扑优化功能,本文将通过一个简单实例进行展示。 一、赵州桥 赵州桥又称安济桥,坐落在河北省赵县洨河上,建于隋朝年间公元595年~605年,由著名匠师李春设计建造,距今已有约1500年的历史,是当今世界上现存最早、保存最完整的古代敞...

TQT_CAE的博客 6027

Halcon实战:5分钟搞定自定义直线卡尺工具(附完整代码下载)

本文详细介绍了如何使用Halcon快速开发自定义直线卡尺工具,通过交互式ROI绘制、边缘检测和直线拟合三个核心函数,实现高效工业视觉检测。文章包含完整代码下载,帮助开发者在5分钟内掌握这一实用工具的开发技巧,提升直线检测的精度和效率。

perl8的博客 251

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

VisionMaster Qt二次开发:图像获取、COM组件渲染与本地化存储实战

本文详细介绍了基于VisionMaster进行Qt二次开发的核心实战流程,涵盖环境搭建、方案加载、图像数据获取、COM组件渲染与本地化存储。重点解析了如何通过COM组件在Qt界面中实时显示图像,以及将VM图像数据转换为QImage并保存为本地文件的关键步骤与常见问题,为工业视觉项目开发提供稳定高效的解决方案。

weixin_29229261的博客 206

PAT 1033. To Fill or Not to Fill (25) 贪心

1033. To Fill or Not to Fill (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 ZHANG, Guochuan With highways available, driv

yxpandjay的博客 272

用逻辑分析仪实测EM4095:125kHz RFID耳标解码的电压与脉宽玄学

本文通过逻辑分析仪实测EM4095芯片,深入解析125kHz RFID耳标解码中的电压与脉宽关联现象。揭示了供电电压对曼彻斯特编码脉宽的影响规律,并提供了一套可落地的调试方法论,包括信号链路解析、逻辑分析仪配置技巧及系统级稳定性提升方案,帮助开发者解决解码不稳定问题。

weixin_30629653的博客 329

AgentScope 实战训练营-构建元规划智能体(Meta Planner Agent)—— 从 0 到 1 完整实现

本文介绍了基于AgentScope框架开发的元规划智能体(Meta Planner Agent)系统。该系统通过任务拆解和子代理编排机制,实现复杂任务的自动化处理。核心架构分为用户层、规划器层和子代理层,其中规划器作为"项目经理"负责任务分解、创建子代理并协调执行流程。关键技术包括AgentScope多智能体框架、DashScope大语言模型、PlanNotebook计划管理工具等。

program哲学 359

1033 To Fill or Not to Fill

第一遍刷pat 题目意思 模拟题真是烦死了! 贪心思想吧 在当前站加满油,如果能开到比当前站便宜的加油站,就加刚刚好过去的油,如果不行的话,就当前先加满,再开到后续最便宜的那个加油站 测试点提示 测试点2 起点处没有加油站 测试点4 牛客网可测,大概可能是当前加满油就可以直接到目的地的那种情况 我的憨憨程序 (模拟题真的不想整理代码了) #include<bits/stdc++.h> #define inf 0x3f3f3f3f using namespace std; struct st

weixin_42986599的博客 235

SAP RAP 校验全流程:从 EML 读取到消息上屏与阻止落库

本文系统梳理了 SAP ABAP RAP 中的校验流程(The Validation Process),结合 Airline/Connection 案例,详细讲解了三类核心校验:语义键唯一性、外键有效性和字段间一致性。文章覆盖了 EML 的 READ ENTITIES 操作、reported-* 与 failed-* 结构的使用方法、消息创建与字段绑定技巧,以及处理草稿数据时的 UNION 查询策略。通过代码示例演示了如何实现校验逻辑、生成错误消息并阻止无效数据持久化,同时提供了常见问题的排查建议。全文注重

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 334

PAT 甲级 1033 To Fill or Not to Fill (25分) 贪心

PAT 甲级 1033 To Fill or Not to Fill (25分) 贪心

星辰不问 195

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

PAT真题练习(甲级)1033 To Fill or Not to Fill (25 分)

PAT真题练习(甲级)1033 To Fill or Not to Fill (25 分) 原题网址:https://pintia.cn/problem-sets/994805342720868352/problems/994805458722734080 A graph which is connected and acyclic can be considered a tree. The ...

Be Quick & Clever & Lucky 403

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

PAT甲级1033 To Fill or Not to Fill (25 分)

1033To 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...

Dexter 269

PAT甲级 1033 To Fill or Not to Fill (25分)

1033 To Fill or Not to Fill (25分) 题目链接:PAT A 1033 题目大意:输入第一行给出四个数,分别是油箱最大容量,杭州到目的地的距离,每单位的油能让汽车跑多远以及加油站的数目。默认初始时汽车的油箱是空的,在任意加油站可以加任意数目的油(不能超过汽车油箱最大容量),要求输出从杭州到目的地所需要油价最少的钱数,如果无法到达目的地,则输出能够行驶的最大距离。 思...

weixin_43684054的博客 289

PAT甲级-1033 To Fill or Not to Fill (25分)

点击链接PAT甲级-AC全解汇总 题目: 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 ...

卷子的博客 371

【PAT甲级】1033 To Fill or Not to Fill (25分)

解题过程的小记录,如有错误欢迎指出。 难度:四星 小导航~题目分析注意点我的解题过程思路bug代码dalao的代码借鉴点 题目分析 注意点 我的解题过程 思路 bug 一开始毫无思路,无从着手 代码 dalao的代码 全部代码因版权原因不放出来,大家可以自行去柳神博客购买或者参考晴神的上机笔记~ 借鉴点 ...

SpicyChicken的自我修养 350

PAT 甲级 1033 Fill or Not to Fill (25分)

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

努力不脱发的程序媛 253

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 way from time to time. Different gas station may give

qq_41001689的博客 179

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

小渣渣的博客 262

PAT A 甲级 1033 To Fill or Not to Fill (25分)

1033 To Fill or Not to Fill (25分) 吐槽 花了好一会儿才反应过来tank是油箱不是坦克。还以为又battle over cities了。 然后这题目很憨。这测点更憨。当然最憨的还是花了这么久才解决这道题的我。 思路 首先到不了的那种情况,很好处理,只要从距离0的站开始第一次发现两相邻站距离大于满油就输出该站距离+满油箱可走长度即可(测点2坑警告,见之后测点部分)。 ...

虚境的博客 225

题146.pat甲级练习-1033 To Fill or Not to Fill (25 分)

文章目录题146.pat甲级练习-1033 To Fill or Not to Fill (25 分)一、题目二、题解 题146.pat甲级练习-1033 To Fill or Not to Fill (25 分) 一、题目 二、题解 本题要你求从开始位置0(注意不一定一开始就是在加油站,得看后面怎么输入的)到指定距离的最少加油钱总和。我们可以采用贪心的策略,由局部最优得到整体最优。大致思路如下: 1.开始我们先把输入的加油站装成结构体数组,然后按照距离和加油钱从小到大排序。 2.每次,我们站在当

Adongua的博客 826

pat 甲级A1033 To Fill or Not to Fill (25分)

题目链接: https://pintia.cn/problem-sets/994805342720868352/problems/994805458722734080 题目分析: 参考代码: #include <iostream> #include <algorithm> #include <vector> using namespa...

dutmathjc的博客 221

【PAT甲级A1033】To Fill or Not to Fill (25分)(c++)

1033 To Fill or Not to Fill (25分) 作者:CHEN, Yue 单位:浙江大学 代码长度限制:16 KB 时间限制:400 ms 内存限制:64 MB 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

小庄同学的博客 250

PAT 甲级 1033 To Fill or Not to Fill (25 分)

题目描述 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is

qq_45478482的博客 155
上一篇: PAT 甲级 1031 Hello World for U(20 分)
下一篇: PAT 甲级 1035 Password(20 分)
UKnowNothing_
博客等级 码龄9年 58粉丝 106原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值