(2)CCF201803-1python實作碰撞的小球
這題也沒有難度…但是注意題目輸出的時候小球的順序是按照輸入的順序輸出的, 所以應該()優先遍歷小球而不是從數軸上遍歷
python 能寫
[0]* (L+1)就是爽啊
代碼實作:
[n, L, t] = [int(x) for x in input().split(' ')]
#第一個表示方向1右-1左, 第二個表示位置
balls = []
rope = [0] * (L+1)
for i in [int(x) for x in input().split(' ')]:
balls.append([1, i])
for time_flying in range(t):
rope = [0] * (1+L)
for i in balls:#球動了
if i[0] == -1:
i[1]-=1
rope[i[1]] += 1
else :
i[1]+=1
rope[i[1]] +=0.1
for i in balls: #球的方向變了
if (i[1]==0) or (i[1]==L):
i[0] = -i[0]
if rope[i[1]] == 1.1:
i[0] = -i[0]
for i in balls:
print(i[1],end = ' ')
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/227540.html
標籤:python
上一篇:Python學習之——串列、字典、實驗低配版非誠勿擾
下一篇:10.回圈陳述句
