【題解】ZeroJudge e974: 2. 座位安排 (Seats)

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e974

Python code (credit: Amy Chou)

R, C, N = map(int, input().split())
seat = []
for i in range(R):
    seat.append([str(i*C+1+j) for j in range(C)])

for i in range(2, N+1):
    if i % 2 == 0:
        # 雙數週時所有人往右橫移一個座位,原本最右邊的人則換到最左邊
        for j in range(R):
            seat[j] = [seat[j][-1]] + seat[j][:-1]
    else:
        # 單數週則是所有人往後移一個座位,原本最後一排的人便換到第一排。
        #tmp = copy.deepcopy(seat[-1])
        tmp = seat[-1]
        for j in range(R-1, 0, -1):
            seat[j] = seat[j-1]
        seat[0] = tmp

for i in range(R):
    print(" ".join(seat[i]))

分享本文 Share with friends