CCF模拟题——碰撞的小球(Python3)
CCF模拟题——碰撞的小球(Python3)

//碰撞的小球
_in = list(map(int, input().split()))
n=_in[0]
L=_in[1]
t=_in[2]

location=list(map(lambda x: int(x), input().split()))

//速度向右为1,向左为-1
s = [1 for i in range(n)]
  
for i in range(t):
    for j in range(n):
        if location[j]==0 or location[j]==L:
            s[j]=-1*s[j]
        //检索是否有碰撞发生
        for k in range(j+1,n):
            //若碰撞,速度反向
            if j!=k and location[j]==location[k]:
                s[j]*=-1
                s[k]*=-1
    //计算每秒小球的位置     
    for m in range(n):
        location[m]+=s[m]

for lo in location:
    print(lo, end=" ")

CCF模拟题——碰撞的小球(Python3)

相关文章:

  • 2022-01-03
  • 2021-07-12
  • 2021-09-14
  • 2021-11-15
  • 2022-01-14
  • 2021-10-08
  • 2021-09-22
  • 2021-06-12
猜你喜欢
  • 2021-11-24
  • 2022-12-23
  • 2021-09-12
  • 2018-03-19
  • 2019-08-11
  • 2021-07-13
  • 2021-07-31
相关资源
相似解决方案