201803-2 碰撞的小球
题目: 见官网
菜鸟一枚,思路较简单
#碰撞的小球
n,l,t=map(int,input().split())
s=list(map(int,input().split()))
def get_index(s):#返回碰撞小球的索引
q=[]
p=[]
for j in range(len(s)):
if s.count(s[j])>1:
q.append(s[j])
q=set(q)
for i in q:
a=s.index(i)
s[a]=0
b=s.index(i)
p.append([a,b])
return p
p=[]
for i in range(len(s)):
p.append([1,s[i]])#1表示小球王数轴正方向移动,-1表示小球往数轴负方向移动
for i in range(t):
ss=set(s)
if len(ss)==len(s):
for j in range(len(p)):
if p[j][1] == l or p[j][1] == 0:
p[j][0] = -p[j][0]
if p[j][0]==1:
p[j][1] = p[j][1] + 1
s[j] = p[j][1]
else:
p[j][1] = p[j][1] - 1
s[j] = p[j][1]
else:
t=get_index(s)
for k in range(len(t)):
p[t[k][0]][0] = -p[t[k][0]][0]
p[t[k][1]][0] = -p[t[k][1]][0]
for j in range(len(p)):
if p[j][1] == l or p[j][1] == 0:
p[j][0] = -p[j][0]
if p[j][0] == 1:
p[j][1] = p[j][1] + 1
s[j] = p[j][1]
else:
p[j][1] = p[j][1] - 1
s[j] = p[j][1]
for i in s:
print(i,end=" ")