[코드트리] 숫자가 가장 큰 인접한 곳으로 동시에 이동 Python
# n, m, t 입력 n, m, t = map(int, input().split()) # grid 입력 grid = [ list(map(int, input().split())) for _ in range(n) ] # count count = [ [0] * n for _ in range(n) ] for _ in range(m): sx, sy = map(int, input().split()) sx, sy = sx - 1, sy - 1 count[sx][sy] = 1 # 함수들 # in_range(x, y) def in_range(x, y): return 0 max_num: # max_num, ax, ay 바꿔주기 max_num, ax, ay = grid[nx][ny], nx, ny # next_count ..
2023. 1. 24.
[코드트리] 벽 짚고 미로 탈출하기 Python
자기자리로 돌아오는 것을 바로 -1 처리했었는데, 잘 생각해보면 4번까지는 지켜봐줘야 한다. # n 입력 n = int(input()) # sx, sy 입력 sx, sy = map(int, input().split()) sx, sy = sx - 1, sy - 1 # maze maze = [ input() for _ in range(n) ] # 함수들 # next_is_empty_without_wall(x, y, d) def next_is_empty_without_wall(x, y, d): # nx, ny nx, ny = x + dxs[d], y + dys[d] # nd nd = (d + 1) % 4 # nxr, nyr nxr, nyr = nx + dxs[nd], ny + dys[nd] # 다음 위치가 범..
2023. 1. 22.
[코드트리] 최적의 십자 모양 폭발 Python
# n 입력 n = int(input()) # grid 입력 grid = [ list(map(int, input().split())) for _ in range(n) ] # 함수들 # pairs_num_of(bombed_grid) def pairs_num_of(bombed_grid): # pair_cnt pair_cnt = 0 # 완전 탐색 for i in range(n): for j in range(n): # 숫자가 있다면, if bombed_grid[i][j]: dxs, dys = [-1, 1, 0, 0], [0, 0, -1, 1] for dx, dy in zip(dxs, dys): nx, ny = i + dx, j + dy # 범위 내에 있고, 짝이 있으면 if in_range(nx, ny) and..
2023. 1. 20.
[코드트리] 삼각형 컨베이어 벨트 Python
# n, t 입력 n, t = map(int, input().split()) # tirangle tirangle = [ list(map(int, input().split())) for _ in range(3) ] # 함수들 # simulate() def simulate(): # temp_1, temp_2, temp_3 temp_1, temp_2, temp_3 = tirangle[0][-1], tirangle[1][-1], tirangle[2][-1] # 옮겨주기 for i in range(n-1, 0, -1): tirangle[0][i] = tirangle[0][i-1] tirangle[1][i] = tirangle[1][i-1] tirangle[2][i] = tirangle[2][i-1] # temp ..
2023. 1. 17.
[코드트리] 2차원 바람 Python
# n, m, q 입력 n, m, q = map(int, input().split()) # grid 입력 grid = [ list(map(int, input().split())) for _ in range(n) ] # winds 입력 winds = [] for _ in range(q): r1, c1, r2, c2 = map(int, input().split()) r1, c1, r2, c2 = r1 - 1, c1 -1, r2 - 1, c2 -1 winds.append((r1, c1, r2, c2)) # 함수들 # in_range(x, y) def in_range(x, y): return 0
2023. 1. 16.
[코드트리] 1차원 바람 Python
# n, m, q 입력 n, m, q = map(int, input().split()) # building building = [ list(map(int, input().split())) for _ in range(n) ] # winds 입력 winds = [] for _ in range(q): r, d = input().split() r = int(r) winds.append((r, d)) # 함수들 # down_simulate(curr_row, curr_dir) def down_simulate(curr_row, curr_dir): # 왼쪽으로부터의 바람이면 if curr_dir == 'L': # temp temp = building[curr_row][-1] # 옮겨주기 for i in range(m-..
2023. 1. 15.