-
[๋ฐฑ์ค] 16935 ๋ฐฐ์ด ๋๋ฆฌ๊ธฐ 3 with PythonPS 2022. 3. 4. 21:40728x90๋ฐ์ํ
๐ BOJ 16935 ๋ฐฐ์ด ๋๋ฆฌ๊ธฐ 3
๐ก ์กฐ๊ฑด
ํฌ๊ธฐ๊ฐ NรM์ธ ๋ฐฐ์ด์ด ์์ ๋, ๋ฐฐ์ด์ ์ฐ์ฐ์ R๋ฒ ์ ์ฉํ๋ ค๊ณ ํ๋ค.
1๋ฒ ์ฐ์ฐ์ ๋ฐฐ์ด์ ์ํ ๋ฐ์ ์ํค๋ ์ฐ์ฐ์ด๋ค.
2๋ฒ ์ฐ์ฐ์ ๋ฐฐ์ด์ ์ข์ฐ ๋ฐ์ ์ํค๋ ์ฐ์ฐ์ด๋ค.
3๋ฒ ์ฐ์ฐ์ ์ค๋ฅธ์ชฝ์ผ๋ก 90๋ ํ์ ์ํค๋ ์ฐ์ฐ์ด๋ค.
4๋ฒ ์ฐ์ฐ์ ์ผ์ชฝ์ผ๋ก 90๋ ํ์ ์ํค๋ ์ฐ์ฐ์ด๋ค.
5, 6๋ฒ์ ๋ฌธ์ ์ฐธ๊ณ์ฒซ์งธ ์ค์ ๋ฐฐ์ด์ ํฌ๊ธฐ N, M๊ณผ ์ํํด์ผ ํ๋ ์ฐ์ฐ์ ์ R์ด ์ฃผ์ด์ง๋ค.
2 โค N, M โค 100, N, M์ ์ง์
1 โค R โค 1,000๋์งธ ์ค๋ถํฐ N๊ฐ์ ์ค์ ๋ฐฐ์ด A์ ์์ Aij๊ฐ ์ฃผ์ด์ง๋ค.
1 โค Aij โค 108์ฐ์ฐ์ ๊ณต๋ฐฑ์ผ๋ก ๊ตฌ๋ถ๋์ด์ ธ ์๊ณ , ๋ฌธ์ ์์ ์ค๋ช ํ ์ฐ์ฐ ๋ฒํธ์ด๋ฉฐ, ์์๋๋ก ์ ์ฉ์์ผ์ผ ํ๋ค.
๊ตฌํ ์ ํ์ ๋ฌธ์
๐ฅ ์์ค ์ฝ๋
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
โจ๏ธ ๋ฌธ์ ํ์ด
- ๋ง ๊ทธ๋๋ก ๊ตฌํ์ ํ๋ ๋ฌธ์ ์๋ค.
๐พ ๋๋์
- ๋ฐฐ์ด์ ๋๋ฆฌ๋๊ฒ ๊ฝค ๊น๋ค๋กญ๊ธดํ๋ฐ, ์ฒ์ฒํ ๊ทธ๋ฆผ์ ๊ทธ๋ฆฌ๋ฉฐ ์ ๋ฆฌํด์ ํ์์ต๋๋ค.
๋ฐ์ํ'PS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 1660 ์บกํด ์ด๋ค์ with Python (0) 2022.03.06 [๋ฐฑ์ค] 1755 ์ซ์๋์ด with Python (0) 2022.03.06 [๋ฐฑ์ค] 15965 K๋ฒ์งธ ์์ with Python (0) 2022.03.04 [๋ฐฑ์ค] 10384 ํฌ๊ทธ๋จ with Python (0) 2022.03.03 [๋ฐฑ์ค] 9742 ์์ด with Python (0) 2022.03.03