Transportation problem python

來源:互聯網
上載者:User
'''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()    

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.