还是一句话,常做常新,每次做都有不一样的想法。大概这就是进步吧(唉,菜的安详)
#分蛋糕
n,k = map(int,input().split())
cakes = list(map(int,input().split()))
ans = 0
weight = 0
for i in cakes:
weight += i
if weight >= k:
ans += 1
weight = 0
if weight != 0:
ans += 1
print(ans)
学生排队
#学生排队
n = int(input()) #学生人数
ans = [i for i in range(n+1)]
location = [i for i in range(n+1)] #记录每个学生的位置
m = int(input()) #调整的次数
for i in range(m):
no,distance = map(int,input().split())
#得到每个学生当前所处的位置,如果其是往前走,则将其前面的同学的位置都往后挪一个
#如果是往后走,则将其从当前所处位置到截止位置出之前的同学都往前移动一位
temp = location[no]
#更新坐标
if distance < 0: #如果是往前移
j = distance
while j < 0:
location[ans[temp+j]] += 1
j += 1
else:
j = distance
while j > 0:
location[ans[temp+j]] -= 1
j -= 1
ans.pop(temp)
ans.insert(temp+distance,no)
location[no] = temp + distance
'''
#直接检索当前学生所在的下标位置
location = ans.index(no)
ans.pop(location)
ans.insert(location+distance,no)
'''
for i in ans[1:]:
print(i,end=" ")