Transportation problem python

来源:互联网 发布:2017网络用语大全 编辑:程序博客网 时间:2024/05/22 17:14
'''Created on 2013-1-28@author: Administrator'''def count(tempr, number, station, i, order):    train = [k for k in range(0,station)]    for n in range(0,station):        train[n] = 0    price = (tempr[i][1]-tempr[i][0])*tempr[i][2]    a = tempr[i][0]    while a<tempr[i][1]:        train[a] = tempr[i][2]        a = a+1     for j in range(0, order):        if i==j:            continue        a = tempr[j][0]        while a<tempr[j][1]:            temp = train[a]+tempr[j][2]            if temp>number:                flag = 1                break            else:                flag = 0                a = a+1        if flag==0:            a = tempr[j][0]            while a<tempr[j][1]:                temp = train[a]+tempr[j][2]                train[a] = temp                a = a+1            tempprice = (tempr[j][1]-tempr[j][0])*tempr[j][2]               price = price+tempprice    return pricedef detect(tempr, number, station, order):    Max = 0    for i in range(0, order):        tempa = count(tempr, number, station, i, order)        if Max<tempa:            Max = tempa    return Max    inf = raw_input()while inf:    tempr = []    #integer = []    i = inf.split(' ')    if i[0]=='0' and i[1]=='0' and i[2]=='0':        break    else:        tempa = int(i[0])        tempb = int(i[1])        tempc = int(i[2])        for k in range(0, tempc):            integer = []            temp = raw_input()            tempi = temp.split(' ')            integer.append(int(tempi[0]))            integer.append(int(tempi[1]))            integer.append(int(tempi[2]))            tempr.append(integer)        r = detect(tempr, tempa, tempb, tempc)        print r    inf = raw_input()    

原创粉丝点击