
문제 https://www.acmicpc.net/problem/7562 7562번: 나이트의 이동 체스판 위에 한 나이트가 놓여져 있다. 나이트가 한 번에 이동할 수 있는 칸은 아래 그림에 나와있다. 나이트가 이동하려고 하는 칸이 주어진다. 나이트는 몇 번 움직이면 이 칸으로 이동할 수 www.acmicpc.net 코드 import collections t = int(input()) for i in range(t): n = int(input()) x, y = map(int, input().split()) rx , ry = map(int, input().split()) dx, dy = [-1,-2, -1, -2, 1, 2, 1, 2], [2, 1, -2, -1, 2, 1, -2, -1] distance =..

문제 https://www.acmicpc.net/problem/2636 2636번: 치즈 아래 과 같이 정사각형 칸들로 이루어진 사각형 모양의 판이 있고, 그 위에 얇은 치즈(회색으로 표시된 부분)가 놓여 있다. 판의 가장자리(에서 네모 칸에 X친 부분)에는 치즈가 놓 www.acmicpc.net 코드 import collections n, m = map(int, input().split()) graph = [list(map(int, input().split())) for _ in range(n)] def bfs(): queue = collections.deque() queue.append((0,0)) check = [[False] * m for _ in range(n)] dx, dy = [-1, 1, ..

문제 https://www.acmicpc.net/problem/2468 2468번: 안전 영역 재난방재청에서는 많은 비가 내리는 장마철에 대비해서 다음과 같은 일을 계획하고 있다. 먼저 어떤 지역의 높이 정보를 파악한다. 그 다음에 그 지역에 많은 비가 내렸을 때 물에 잠기지 않는 www.acmicpc.net 코드 import collections n = int(input()) graph = [list(map(int, input().split())) for _ in range(n)] def bfs(x, y, k): queue = collections.deque() queue.append((x,y)) count = 1 dx, dy = [-1, 1, 0, 0], [0, 0, -1, 1] while queue..

문제 https://www.acmicpc.net/problem/2667 2667번: 단지번호붙이기 과 같이 정사각형 모양의 지도가 있다. 1은 집이 있는 곳을, 0은 집이 없는 곳을 나타낸다. 철수는 이 지도를 가지고 연결된 집의 모임인 단지를 정의하고, 단지에 번호를 붙이려 한다. 여 www.acmicpc.net 코드 import collections n = int(input()) graph = [list(map(int,input().strip())) for _ in range(n)] check = [[False]*n for _ in range(n)] def bfs(x,y): count = 1 check[x][y] = True queue = collections.deque() queue.append((..