python pat-1014甲 Waiting in Line

python pat-1014甲 Waiting in Line 测试点详解 及测试点实例


看到没人用python解决过这道题,想发表篇文章来展示一下python的解法。
题目链接:
https://pintia.cn/problem-sets/994805342720868352/problems/994805498207911936

第一次解这道题就对了一个测试点就是那个例子
所以改了几次大致知道每个测试点
主要的测试点就是540要输出Sorry,
还有就是列表不要超出范围了
这里主要给出两个测试点实例全部通过应该就差不多了
3 5 8 1
1 2 6 4 3 2 55 66
1 2 3 4 5 6 7 8

5 3 15 10
1 2 6 4 3 534 2 5 8 10 33 22 55 88 77
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15


n,m,k,q=[int(x) for x in input().split()]
people_time_list=[int(x) for x in input().split()]
line_time_list=[0 for x in range(n)]
dict1={}
list_wait=[]

for j in range(m):
    list_kaishi=[]
    for i in range(n):
        if j*n+i>=k:
            pass
        else:
            line_time_list[i]=line_time_list[i]+people_time_list[j*n+i]
            dict1[j*n+i+1]=line_time_list[i]
            list_kaishi.append(line_time_list[i])
    list_wait.append(list_kaishi)
for i in range(n*m,k):
    index=list_wait[0].index(min(list_wait[0]))
    for l in range(m-1):
        list_wait[l][index]=list_wait[l+1][index]
    line_time_list[index] = line_time_list[index] + people_time_list[i]
    list_wait[m-1][index]=line_time_list[index]
    dict1[i+1] = line_time_list[index]
list1=[int(x) for x in input().split()]
for i in list1:
    hour=dict1[i]//60+8
    minute=dict1[i]%60
    time_now=dict1[i]-people_time_list[i-1]
    if time_now>=540:
        print("Sorry")
    elif dict1[i]>=600:
        print("Sorry")
    elif hour<10 and minute<10:
        print("0"+str(hour)+":"+"0"+str(minute))
    elif hour<10:
        print("0" + str(hour) + ":" + str(minute))
    elif minute<10:
        print(str(hour) + ":" + "0" + str(minute))
    else:
        print(str(hour) + ":"+ str(minute))

发现和别人的百行左右的代码比起来我的还是很简短的

你可能感兴趣的:(编程,pat甲,1014,python)