[백준] 16197번 - 두 동전 (파이썬)
# 두 동전 import copy from collections import deque N, M = map(int, input().split()) arr = [] money = deque() for i in range(N): arr.append(list(input().strip())) for j in range(M): if arr[i][j] == 'o': money.append((i, j)) arr[i][j] = '.' visited = set() visited.add(''.join(map(str, money))) dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def bfs(): q = deque() q.append((0, money)) while q: cnt, now = q.pop..
2022. 4. 20.
[백준] 2234번 - 성곽 (파이썬)
# 성곽 import sys from collections import deque from collections import defaultdict input = sys.stdin.readline M, N = map(int, input().split()) arr = [] for _ in range(N): arr.append(list(map(int, input().split()))) # 방향은 8,4,2,1 순서로 남,동,북,서 dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] def bfs(a, b, arr, visited, room_num): q = deque() q.append((a, b)) visited[a][b] = room_num room_size = 1 while q: x, y..
2022. 4. 17.