FeelingXD

[๋ฐฑ์ค€ - 16926] ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 1 ๐Ÿ˜„ ๋ณธ๋ฌธ

์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

[๋ฐฑ์ค€ - 16926] ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 1 ๐Ÿ˜„

FeelingXD 2024. 2. 24. 19:03

โ“ Problem

๐Ÿค” How

๋‹ค์ฐจ์› ๋ฐฐ์—ด์„ ๋Œ๋ ค์•ผํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋‚˜์˜จ๋‹ค๋ฉด ๊ธฐ์กด ๋ฐฐ์—ด์„ ๋ณต์‚ฌ ํ›„ ์ด๋™ ์œ„์น˜์—๋”ฐ๋ฅธ ์›€์ง์ž„์„ ์ƒ๊ฐํ•˜๋Š” ํŽธ์ด๋‹ค. ๋ณต์‚ฌํ•˜๋Š” ๊ณผ์ •์—์„œ ๊ณต๊ฐ„๋ณต์žก๋„์™€ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ์†Œ๋ชจ ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๊ฐœ์ธ์ ์œผ๋กœ ์ด๋Ÿฌํ•œ ํ’€์ด๋ฅผ ์„ ํ˜ธํ•œ๋‹ค.

๋ฌธ์ œ๋งŒ ์ฝ์–ด๋ณด๋ฉด ์ •๋ง ์ง๊ด€์ ์ธ ๋ฌธ์ œ์ด๋‹ค. ๋‹จ์ˆœํžˆ ๋ฐฐ์—ด์„ ๋Œ๋ ค์„œ ๋งŒ๋“ค์–ด์ง€๋Š” ๋ฐฐ์—ด์„ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ. ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ํŠน์ˆ˜ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•œ๋‹ค๊ธฐ๋ณด๋‹ค๋Š” ์ง๊ด€์ ์œผ๋กœ ์ฝ๊ณ  ๊ตฌํ˜„์— ํฌ์ปค์Šค๋ฅผ ๋งž์ถ”๋Š” ๋ฌธ์ œ์ด๋‹ค.

๊ฐ„๋‹จํ•˜๊ฒŒ ํ•ต์‹ฌ์ด๋˜๋Š” ๋ฐฐ์—ด์„ ๋Œ๋ฆฌ๋Š” ์ฝ”๋“œ์—๋Œ€ํ•ด์„œ๋งŒ ์ถ”๊ฐ€์ ์œผ๋กœ ์„ค๋ช…ํ•˜๊ณ ์ž ํ•œ๋‹ค.

def rotate_board(board, round):
    global M, N
    copy_board = [line[:] for line in board]
    square = min(M, N)
    # ๋ณด์ •
    M -= 1
    N -= 1
    for r in range(round):  # ๋ผ์šด๋“œ ๋งŒํผํšŒ์ „
        if r:  # ํšŒ์ „์ˆ˜๊ฐ€ 0์ด์•„๋‹ˆ๋ฉด copy_board ๋ณต์‚ฌํ•˜๊ธฐ
            board = [line[:] for line in copy_board]
        for i in range(square // 2):
            for x in range(M - i, i, -1):
                copy_board[i][x - 1] = board[i][x]
            for y in range(i, N - i):
                copy_board[y + 1][i] = board[y][i]
            for x in range(i, M - i):
                copy_board[N - i][x + 1] = board[N - i][x]
            for y in range(N - i, i, -1):
                copy_board[y - 1][M - i] = board[y][M - i]
    return copy_board

๋ฐฐ์—ด ๋Œ๋ฆฌ๋Š” ํ•จ์ˆ˜

๐Ÿค” - ์™œ M ๊ณผ N ์„ -1 ํ•ด์คŒ์œผ๋กœ์จ ๋ณด์ •ํ•˜๋‚˜์š” ?
โœจ - ๋ฌธ์ œ ์š”๊ตฌ์‚ฌํ•ญ์—์„œ ๋ฐฐ์—ด์˜ ์ฒ˜์Œ์‹œ์ž‘์€ 1,1 ๋กœ ํ‘œํ˜„ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋Œ€๋ถ€๋ถ„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ (์—ฌ๊ธฐ์„œ๋Š” python ์„ ์‚ฌ์šฉ) ๋ฐฐ์—ด์€ 0 ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ธฐ์— ๊ฐ -1 ์„ ํ•ด์คŒ์œผ๋กœ ์จ ๋ณด์ • ํ–ˆ์Šต๋‹ˆ๋‹ค.

โ— Solve

# ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 1
import sys

input = sys.stdin.readline


def get_board(rows):
    return [list(map(int, input().split())) for _ in range(rows)]


def rotate_board(board, round):
    global M, N
    copy_board = [line[:] for line in board]
    square = min(M, N)
    # ๋ณด์ •
    M -= 1
    N -= 1
    for r in range(round):  # ๋ผ์šด๋“œ ๋งŒํผํšŒ์ „
        if r:  # ํšŒ์ „์ˆ˜๊ฐ€ 0์ด์•„๋‹ˆ๋ฉด copy_board ๋ณต์‚ฌํ•˜๊ธฐ
            board = [line[:] for line in copy_board]
        for i in range(square // 2):
            for x in range(M - i, i, -1):
                copy_board[i][x - 1] = board[i][x]
            for y in range(i, N - i):
                copy_board[y + 1][i] = board[y][i]
            for x in range(i, M - i):
                copy_board[N - i][x + 1] = board[N - i][x]
            for y in range(N - i, i, -1):
                copy_board[y - 1][M - i] = board[y][M - i]
    return copy_board


def print_board(board):
    for line in board:
        print(*line)


def solution():
    global N, M
    N, M, R = map(int, input().split())  # ์„ธ๋กœ,๊ฐ€๋กœ,ํšŒ์ „
    board = get_board(N)
    board = rotate_board(board, R)
    print_board(board)

    pass


if __name__ == "__main__":  # ์‹คํ–‰๋˜๋Š” ๋ถ€๋ถ„
    solution()
    pass