CCF CSP 201703-1/2 分蛋糕/学生排队 python

201703-1 分蛋糕

CCF CSP 201703-1/2 分蛋糕/学生排队 python_第1张图片
满分实现:

n,k = map(int,input().split())
a_list = list(map(int,input().split()))
a=0
child = 0
for i in range(len(a_list)):
    if a == 0 and a_list[i]>=k:
        child+=1
        continue
    if a+a_list[i] >=k:
        child+=1
        a = 0
    else:
        if i == len(a_list)-1:
            child+=1
        else:
            a+=a_list[i]
print(child)
   

201703-2 学生排队

CCF CSP 201703-1/2 分蛋糕/学生排队 python_第2张图片
满分实现:

n = int(input())
m = int(input())
queue = [i+1 for i in range(n)]

for i in range(m):
    data,position = map(int,input().split())
    index = queue.index(data)
    after_position = index+position
    queue.remove(data)
    queue.insert(after_position,data)

for i in queue:
    print(i,end=" ")

你可能感兴趣的:(CCF,CSP,python)