美文网首页
201803-2(Python实现)

201803-2(Python实现)

作者: tmax | 来源:发表于2019-12-09 22:18 被阅读0次
    n, L, t = list( map(int, input().split()) )
    tmpList = list(map(int, input().split()) )
    sortedTmpList = sorted(tmpList)
    posList = [0] + sortedTmpList
    referList = []
    for ele in tmpList:
        for i in range(len(sortedTmpList)):
            if ele == sortedTmpList[i]:
                referList.append(i)
                break
    direList = [1]*(n+1)
    
    for i in range(1, t+1):
        for j in range(1, n+1):
            posList[j] += direList[j]*1
            if posList[j] > L:
                posList[j] = 2*L - posList[j]
                direList[j] *= -1
            if posList[j] < 0:
                posList[j] = -posList[j]
                direList[j] *= -1
        for j in range(1, n):
            if posList[j]==posList[j+1] and direList[j]==-direList[j+1]:
                direList[j] *= -1
                direList[j+1] *= -1
    
    for idx in referList:
        print(posList[idx+1],end=' ')
                    
    

    相关文章

      网友评论

          本文标题:201803-2(Python实现)

          本文链接:https://www.haomeiwen.com/subject/wjoigctx.html