以如下格式输入数据: L1 L2 L3 C1 C2 C3 A B N a[2] a[3] …… a[N]
可能有多组测试数据,对于每一组数据, 根据输入,输出乘客从A到B站的最小花费。
1 2 3 1 2 3 1 2 2 2
2
def fareNum(distance):
if distance <= length[0]:
return costs[0]
elif distance <= length[1]:
return costs[1]
else:
return costs[2]
try:
while True:
tempInput = list(map(int,input().split()))
length = tempInput[:3]
costs = tempInput[3:]
a,b = list(map(int,input().split()))
if a > b:
a,b = b,a
n = int(input())
distances = [0,0] #distances[i]表示第一个车站到第i个车站的路程
for i in range(n-1):
distances.append(int(input()))
spend = [float('inf')] * (n+1) #spend[i]表示车站a到车站i的最小花费
spend[a] = 0
for i in range(a+1,b+1):
temp = i - 1 #从前一个开始查找最少花费
while temp >= a and (distances[i]-distances[temp]) <= length[2]:
spend[i] = min(spend[i],spend[temp]+fareNum(distances[i]-distances[temp]))
temp -= 1
print(spend[b])
except Exception:
pass