A1033. To Fill or Not to Fill】的更多相关文章

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 g…
Source: PAT A1033 To Fill or Not to Fill (25 分) Description: 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. D…
 题目链接:http://www.patest.cn/contests/pat-a-practise/1033 题目: 1033. To Fill or Not to Fill (25) 时间限制 10 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 ZHANG, Guochuan With highways available, driving a car from Hangzhou to any other city is easy. But…
PAT A 1033 To Fill or Not to Fill 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 gi…
1033. To Fill or Not to Fill (25) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 ZHANG, Guochuan 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 fin…
PAT甲级1033. To Fill or Not to Fill 题意: 有了高速公路,从杭州到任何其他城市开车很容易.但由于一辆汽车的坦克容量有限,我们不得不在不时地找到加油站.不同的加油站可能会给不同的价格.您被要求仔细设计最便宜的路线. 输入规格: 每个输入文件包含一个测试用例.对于每种情况,第一行包含4个正数:Cmax(<= 100),坦克的最大容量; D(<= 30000),杭州与目的地城市的距离; Davg(<= 20),汽车可以运行的单位气体的平均距离;和N(<=…
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 gi…
题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: 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 fro…
1033. To Fill or Not to Fill (25) 时间限制 10 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 ZHANG, Guochuan 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 fin…
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…
1033 To Fill or Not to Fill 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 dif…
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…
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…
一.技术总结 是贪心算法的题目,题目主要考虑的问题有几个,是否会在第一个加油站的最近距离大于0,如果是这样那么直接输出答案,因为初始油箱没有汽油: 第二个是如何选定加油站,如果在可到达距离范围类,我们优先考虑比当前加油站价格更低的,然后如果有,就直接到达这里,如果没有那也要选出这里面价格最低的那个加油站, 然后在当前加油站,加满油箱.这样可以更加的省钱,那么油箱会多出油行驶距离(leftdis = Cmax*Davg -(minPriceDis - nowdis)). 可以开始判断最后结局了,如…
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…
#include <cstdio> #include <cstdlib> #include <vector> #include <algorithm> using namespace std; int main() { int N; double mcap, dist, davg; scanf("%lf%lf%lf%d", &mcap, &dist, &davg, &N); double price, id…
题目描述: 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…
//贪心算法解决加油站选择问题 //# include<iostream> # include<stdio.h> using namespace std; # include<algorithm> struct Node { float p, d; }; bool cmp(Node a, Node b) { return a.d < b.d; } int main() { Node node[]; float Cmax, D, Davg, distance, pr…
题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1033 此题是一道贪心算法题,难度较大,关键在于贪心策略的选择: #include <cstdio> #include <vector> #include <algorithm> #include <climits> using namespace std; struct GasStation { double price; double distance…
题目地址:http://ac.jobdu.com/problem.php?pid=1437 题目描述: 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…
题目大意:小明从杭州去往某目的地,要经过一些加油站,每个加油站的价格不一样.若能顺利到达,求加油费用最少为多少,否则求出能行驶的最远距离. 思路:贪心算法 1>若下一加油站的价格更便宜,则只需走到下一加油站即可. 2>若下一结点的价格没有该节点便宜 1.若将油箱加满,看看在其能到达的最远距离内,是否有比该点更便宜的站点.若有,则正好到达这个跟便宜的点即可:否则,将油箱加满,然后到达这段距离内价格最小的点(除当前点外). 代码如下: #include<cstdio> #include…
PAT-A最后一个问题.最后做出来... 贪婪,通过局部优化全局优化. 1. 该加油站按距离升序排列 2. 记录气体台当前所在index,目前的汽油.开支.在您的整个背部 3. 遍历中有两种情况: 1) 若发现油价比index更低的站next: 立即跳到该站(此时可能须要加油),不再继续遍历 -- 由于即使想要到达next后面的站,能够通过在next站购买更廉价的汽油来实现 2) 没有发现油价比index更低的站,则选择全部站中油价最低的站作为next: 此时考虑能否通过index抵达终点,若能…
题目描写叙述 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…
转自:https://www.cnblogs.com/XBWer/p/3866486.html 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…
题目如下: 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…
模拟先说一下例子,最后为方便起见,在目的地安增加一个费用为0的加油站0 1 2 3 4 5 6 7 87.1 7.0 7.2 6.85 7.5 7.0 7.3 6.0 00 150 200 300 400 600 1000 1250 1300车子加满了最多开50*12=600的距离0.第0个加油站600以内中,找有没有比7.1小的找到7.0,那么只需要加跑150距离的汽油即可费用(150/12)*7.1=88.75到第1个加油站 1.同样往后600距离内找比7.0小的找到6.85,那么只需要加跑…
PAT-A的最后一题,最终做出来了... 是贪心,通过局部最优获得全局最优. 1. 将加油站按距离升序排序 2. 记录当前所在的加油站index,存有的汽油,花费.向后遍历全部 该站可抵达的加油站 3. 遍历中有两种情况: 1) 若发现油价比index更低的站next: 立即跳到该站(此时可能须要加油),不再继续遍历 -- 由于即使想要到达next后面的站,能够通过在next站购买更廉价的汽油来实现 2) 没有发现油价比index更低的站,则选择全部站中油价最低的站作为next: 此时考虑能否通…
贪心.注意x=0处没有加油站的情况. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; struct X { double cost, x, v; int…
题目描写叙述: 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 ar…
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…