DFS,BFS - 음료수 얼려먹기
n, m = map(int, input().split()) a = [] for i in range(n): a.append(list(map(int, input()))) def dfs(x, y): if x = n or y = m: # 범위 지정 넘어가면 return False # False 반환 if a[x][y] == 0: a[x][y] = 1 dfs(x-1, y) dfs(x, y-1) dfs(x+1, y) dfs(x, y+1) return True return False result = 0 for i in range(n): for j in range(m): if dfs(i, j) == True: result += 1 print(result)
2022. 6. 26.
구현 - 게임 개발
# 게임개발 n, m = map(int, input().split()) d = [[0] * m for _ in range(n)] x, y, direction = map(int, input().split()) d[x][y] = 1 array = [] for i in range(n): array.append(list(map(int, input().split()))) dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] def turn_left(): global direction direction -= 1 if direction == -1: direction = 3 count = 1 turn_time = 0 while True: turn_left() nx = x + dx[direction] ny..
2022. 6. 26.
구현 - 왕실의 나이트
n = input() r = int(n[1]) c = int(ord(n[0])) - 96 d = [(-2, -1), (-1, -2), (1, -2), (2, -1), (2, 1), (1, 2), (-1, 2), (-2, 1)] dap = 0 for direction in d: n_r = r + direction[0] n_c = c + direction[1] if n_r >= 1 and n_r = 1 and n_c
2022. 6. 26.