由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - gas station min cost
相关主题
问个问题Amex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡
请问这里有没有人去参加9月21号的BOSTON的Boston Job Fair?Amex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡
Stat/Econ/Finance/Math Experienced Position AvailableAmex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡
问一个brain teaser question: How many gas station is there in the US?Gas station II
想提高英语,有什么推荐的RADIO STATION吗?gas station这道题有个case过不了
两道跟circular linkedlist相关的题。gas station的解法,我觉得有不完备的可能---貌似又是完备的。
Amex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡从NJ Newark Airport到penn station有地铁吗? (转载)
Amex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡急问有没有面试过bloomberg的senior calculations programmer的?
相关话题的讨论汇总
话题: gas话题: station话题: tank话题: your话题: gallons
进入JobHunting版参与讨论
1 (共1页)
s******e
发帖数: 108
1
You are planning a cross-country trip
along a straight highway with n + 1 gas stations.
You start at gas station 0,
and the distance to gas station i is di miles (0 = d0 < d1 < . . . < dn).
Your car’s gas tank holds G > 0 gallons,
and your car travels m > 0 miles on each gallon of gas.
You start with an full tank of gas[G gallons] (at gas station 0),
and your destination is gas station n.
You may not run out of gas,
although you may arrive at a gas station with an empty tank.
The price of gas at gas station i is pi dollars per gallon (not necessarily
an integer). You cannot sell gas. Give an algorithm to calculate the cost of
the cheapest possible trip.
c**s
发帖数: 159
2
贪心 油“分块” 最后可退回
记录油箱里的油量 pair (price, amount)
起初(0, G)因为开始的油不花钱。
我们保证油箱“总是满的” 即所有amount的总和始终为G 但只有用掉的油才花钱。
每到一个加油站 把油加满 但不计算钱。 即加入新的(price, amount)。 存pair得
的结构实际上是个堆 或者multiset (c++)。因为到下个加油站用油的时候 我们从存的
最便宜的块开始用 并且用多少要算钱了 (如果一块用完 则删掉 否则减少amount,直
到可以走到下一个加油站)
本质就是个堆的插入和删除

:You are planning a cross-country trip
:along a straight highway with n + 1 gas stations.
J*****4
发帖数: 1
3
每到一个加油站,计算剩余油可以走多远,这个范围内有没比此加油站更便宜的油,如
果有就不加油,直接向前开
如果没有,则边加油(以加满为终止条件)边计算多走的范围内有没有比此加油站更便宜
的油,如果有则加油到此为止break,向前开。
1 (共1页)
进入JobHunting版参与讨论
相关主题
about how to test a calculator program on computer想提高英语,有什么推荐的RADIO STATION吗?
算法问题两道跟circular linkedlist相关的题。
请教一下超大图的存储问题Amex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡
external sorting 的问题Amex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡
问个问题Amex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡
请问这里有没有人去参加9月21号的BOSTON的Boston Job Fair?Amex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡
Stat/Econ/Finance/Math Experienced Position AvailableAmex Blue Cash preferred 6%现金回扣+$150bonus超市专用信用卡
问一个brain teaser question: How many gas station is there in the US?Gas station II
相关话题的讨论汇总
话题: gas话题: station话题: tank话题: your话题: gallons