ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [๋ฐฑ์ค€] 16935 ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 3 with Python
    PS 2022. 3. 4. 21:40
    728x90
    ๋ฐ˜์‘ํ˜•

    ๐Ÿ“Œ BOJ 16935 ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 3

    ๐Ÿ’ก ์กฐ๊ฑด

    1. ํฌ๊ธฐ๊ฐ€ Nร—M์ธ ๋ฐฐ์—ด์ด ์žˆ์„ ๋•Œ, ๋ฐฐ์—ด์— ์—ฐ์‚ฐ์„ R๋ฒˆ ์ ์šฉํ•˜๋ ค๊ณ  ํ•œ๋‹ค.
      1๋ฒˆ ์—ฐ์‚ฐ์€ ๋ฐฐ์—ด์„ ์ƒํ•˜ ๋ฐ˜์ „์‹œํ‚ค๋Š” ์—ฐ์‚ฐ์ด๋‹ค.
      2๋ฒˆ ์—ฐ์‚ฐ์€ ๋ฐฐ์—ด์„ ์ขŒ์šฐ ๋ฐ˜์ „์‹œํ‚ค๋Š” ์—ฐ์‚ฐ์ด๋‹ค.
      3๋ฒˆ ์—ฐ์‚ฐ์€ ์˜ค๋ฅธ์ชฝ์œผ๋กœ 90๋„ ํšŒ์ „์‹œํ‚ค๋Š” ์—ฐ์‚ฐ์ด๋‹ค.
      4๋ฒˆ ์—ฐ์‚ฐ์€ ์™ผ์ชฝ์œผ๋กœ 90๋„ ํšŒ์ „์‹œํ‚ค๋Š” ์—ฐ์‚ฐ์ด๋‹ค.
      5, 6๋ฒˆ์€ ๋ฌธ์ œ ์ฐธ๊ณ 

    2. ์ฒซ์งธ ์ค„์— ๋ฐฐ์—ด์˜ ํฌ๊ธฐ N, M๊ณผ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ์—ฐ์‚ฐ์˜ ์ˆ˜ R์ด ์ฃผ์–ด์ง„๋‹ค.
      2 โ‰ค N, M โ‰ค 100, N, M์€ ์ง์ˆ˜
      1 โ‰ค R โ‰ค 1,000

    3. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๋ฐฐ์—ด A์˜ ์›์†Œ Aij๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.
      1 โ‰ค Aij โ‰ค 108

    4. ์—ฐ์‚ฐ์€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด์ ธ ์žˆ๊ณ , ๋ฌธ์ œ์—์„œ ์„ค๋ช…ํ•œ ์—ฐ์‚ฐ ๋ฒˆํ˜ธ์ด๋ฉฐ, ์ˆœ์„œ๋Œ€๋กœ ์ ์šฉ์‹œ์ผœ์•ผ ํ•œ๋‹ค.

    5. ๊ตฌํ˜„ ์œ ํ˜•์˜ ๋ฌธ์ œ

    ๐Ÿ–ฅ ์†Œ์Šค ์ฝ”๋“œ

    from sys import stdin
    
    n, m, r = map(int, stdin.readline().split())
    board = []
    for _ in range(n):
        board.append(list(map(int, stdin.readline().split())))
    
    command = list(map(int, list(stdin.readline().split())))
    for i in range(r):
        if command[i] == 1:
            length = len(board)
            for j in range(length // 2):
                board[j], board[length - 1 - j] = board[length - 1 - j], board[j]
    
        elif command[i] == 2:
            for i in range(len(board)):
                board[i] = list(reversed(board[i]))
    
        elif command[i] == 3:
            if len(board) == n:
                new_board = [[0] * n for _ in range(m)]
                for j in range(m):
                    for k in range(n):
                        new_board[j][n - 1 - k] = board[k][j]
            else:
                new_board = [[0] * m for _ in range(n)]
                for j in range(n):
                    for k in range(m):
                        new_board[j][m - 1 - k] = board[k][j]
    
            board = new_board
    
        elif command[i] == 4:
            if len(board) == n:
                new_board = [[0] * n for _ in range(m)]
                for j in range(m - 1, -1, -1):
                    for k in range(n - 1, -1, -1):
                        new_board[(m - 1) - j][k] = board[k][j]
            else:
                new_board = [[0] * m for _ in range(n)]
                for j in range(n - 1, -1, -1):
                    for k in range(m - 1, -1, -1):
                        new_board[(n - 1) - j][k] = board[k][j]
    
            board = new_board
    
        elif command[i] == 5:
            r, c = len(board), len(board[0])
            new_board = [[0] * c for _ in range(r)]
    
            arr1 = [item[:c // 2] for item in board[:r // 2]]
            arr2 = [item[c // 2:] for item in board[:r // 2]]
            arr3 = [item[c // 2:] for item in board[r // 2:]]
            arr4 = [item[:c // 2] for item in board[r // 2:]]
    
            for j in range(r // 2):
                new_board[j] = arr4[j] + arr1[j]
    
            for j in range(r // 2, r):
                new_board[j] = arr3[j - r // 2] + arr2[j - r // 2]
            board = new_board
    
        elif command[i] == 6:
            r, c = len(board), len(board[0])
            new_board = [[0] * c for _ in range(r)]
    
            arr1 = [item[:c // 2] for item in board[:r // 2]]
            arr2 = [item[c // 2:] for item in board[:r // 2]]
            arr3 = [item[c // 2:] for item in board[r // 2:]]
            arr4 = [item[:c // 2] for item in board[r // 2:]]
            for j in range(r // 2):
                new_board[j] = arr2[j] + arr3[j]
    
            for j in range(r // 2, r):
                new_board[j] = arr1[j - r // 2] + arr4[j - r // 2]
            board = new_board
    
    for arr in board:
        print(*arr)

    ๐Ÿ”– ์˜ˆ์ œ ๋ฐ ์‹คํ–‰๊ฒฐ๊ณผ

    ์˜ˆ์ œ

    6 8 6
    3 2 6 3 1 2 9 7
    9 7 8 2 1 4 5 3
    5 9 2 1 9 6 1 8
    2 1 3 8 6 3 9 2
    1 3 2 8 7 9 2 1
    4 5 1 9 8 2 1 3
    1 2 3 4 5 6

    ์‹คํ–‰๊ฒฐ๊ณผ

    3 1 2 8 9 1 5 4
    1 2 9 7 8 2 3 1
    2 9 3 6 8 3 1 2
    8 1 6 9 1 2 9 5
    3 5 4 1 2 8 7 9
    7 9 2 1 3 6 2 3

    โŒจ๏ธ ๋ฌธ์ œ ํ’€์ด

    1. ๋ง ๊ทธ๋Œ€๋กœ ๊ตฌํ˜„์„ ํ•˜๋Š” ๋ฌธ์ œ์˜€๋‹ค.

    ๐Ÿ’พ ๋Š๋‚€์ 

    1. ๋ฐฐ์—ด์„ ๋Œ๋ฆฌ๋Š”๊ฒŒ ๊ฝค ๊นŒ๋‹ค๋กญ๊ธดํ•œ๋ฐ, ์ฒœ์ฒœํžˆ ๊ทธ๋ฆผ์„ ๊ทธ๋ฆฌ๋ฉฐ ์ •๋ฆฌํ•ด์„œ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค.
    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.