ZJU PAT 1014 Waiting in Line

银行有n个窗口,每个窗口可以排m个人,在n×m以外的顾客会选择最短的队列进行排队。给出每个顾客需要消耗的时间长度,求出每个顾客具体结束服务的时间。没什么算法也没什么技巧,可以练习一下python里datetime模块的使用方法

 1 import time, datetime
 2 start = datetime.datetime(2013,1,3,8,0,0)
 3 end = datetime.datetime(2013,1,3,17,0,0)
 4 N, M, K, Q = raw_input().split()
 5 cus = raw_input().split()
 6 N = int(N)
 7 K = int(K)
 8 M = int(M)
 9 queue = [[0] for x in range(N)] 
10 custime =[]
11 for i in range(K):    
12     a = 0
13     if i < N*M:            
14         a = i%N
15     else:
16         list = [queue[j][1] for j in range(N)]
17         a = list.index(min(list))
18     tmp = queue[a][-1]    
19     queue[a].append(tmp+int(cus[i]))
20     custime.append((tmp, queue[a][-1]))
21     if i>=N*M:
22         queue[a].pop(1)
23 ask = raw_input().split()
24 for item in ask:
25     mystart, myend = custime[int(item)-1]
26     if start+datetime.timedelta(minutes=mystart) >= end:
27         print "Sorry"
28     else:
29         print (start+datetime.timedelta(minutes=myend)).strftime('%H:%M')

 

posted @ 2013-01-27 21:59  S.Zhang  阅读(592)  评论(0编辑  收藏  举报