运油问题(3000 加仑,1000 英里,容量 1000
Oil Transport
题目详情
一艘油轮要把 3000 加仑油从港口 X 运到港口 Y,两港相距 1000 英里。
船每行驶 1 英里都会固定漏掉 1 加仑油(与载油量无关),且任何时刻最多只能装 1000 加仑。
船可以在途中任意位置建立储油点:把油卸下存放,之后再来取。
问:在最优方案下,最多能从 X 运到 Y 多少加仑油?(四舍五入到最接近的整数加仑。)
An oil tanker ship is transporting gallons of oil from Port to Port which are miles apart. However, the ship loses gallon of oil for every mile it travels from spillage (at a constant rate) and can carry a max of gallons at any time. The ship can also dump any oil that it is carrying at any number of storage ports on the way from Port to Port and pick it up later. Assuming an optimal travel plan where you decide where to place any number of storage ports and how to carry the oil, how many gallons can you transport from Port to Port (round to the nearest gallon)?
解析
这是经典“分段搬运 / 沙漠运香蕉”问题。
当剩余油量需要分成 趟运输(每趟最多 1000)时,为把油向前推进 1 英里,需要有 次穿越该 1 英里(来回搬运),因此每推进 1 英里净消耗 加仑。
- 初始 3000 加仑,需要 趟,净消耗率 5 加仑/英里。推进 英里直到剩余 2000:
- 剩余 2000 加仑,需要 趟,净消耗率 3 加仑/英里。推进 英里直到剩余 1000:
此时已前进 英里。
- 剩余 1000 加仑只需 1 趟,消耗率 1 加仑/英里。剩余路程为
到达 Y 时剩余油为
四舍五入得到 加仑。