def Bfs() :
global b, n, t, l
queue = [[n[0]-1], [n[1]-1]]
l[n[0]-1][n[1]-1] = 'n'
l[t[0]-1][t[1]-1] = 't'
while len(queue) != 0:
q = queue.pop(0)
if q[0] + 2 < b and q[1] + 1 > 0 and l[q[0] + 2][q[1] + 1] == 0 or 't':
queue.append([q[0] + 2, q[1] + 1])
l[q[0] + 2][q[1] + 1] = 'n'
if q[0] + 2 < b and q[1] - 1 > 0 and l[q[0] + 2][q[1] - 1] == 0 or 't':
queue.append([q[0] + 2, q[1] - 1])
l[q[0] + 2][q[1] - 1] = 'n'
if q[0] + 1 < b and q[1] + 2 > 0 and l[q[0] + 1][q[1] + 2] == 0 or 't':
queue.append([q[0] + 1, q[1] + 2])
l[q[0] + 1][q[1] + 2] = 'n'
if q[0] - 1 < b and q[1] + 2 > 0 and l[q[0] - 1][q[1] + 2] == 0 or 't':
queue.append([q[0] + 2, q[1] - 1])
l[q[0] - 1][q[1] + 2] = 'n'
if q[0] - 2 < b and q[1] + 1 > 0 and l[q[0] - 2][q[1] + 1] == 0 or 't':
queue.append([q[0] - 2, q[1] + 1])
l[q[0] - 2][q[1] + 1] = 'n'
if q[0] - 2 < b and q[1] - 1 > 0 and l[q[0] - 2][q[1] - 1] == 0 or 't':
queue.append([q[0] - 2, q[1] - 1])
l[q[0] - 2][q[1] - 1] = 'n'
if q[0] + 1 < b and q[1] - 2 > 0 and l[q[0] + 1][q[1] - 2] == 0 or 't':
queue.append([q[0] + 1, q[1] - 2])
l[q[0] + 1][q[1] - 2] = 'n'
if q[0] - 1 < b and q[1] - 2 > 0 and l[q[0] - 1][q[1] - 2] == 0 or 't':
queue.append([q[0] - 1, q[1] - 2])
l[q[0] - 1][q[1] - 2] = 'n'
b = int(input())
n = list(map(int, input().split()))
t = list(map(int, input().split()))
l = [[0 for _ in range(b)] for _ in range(b)]
Bfs()top of page

실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
250622
250622
댓글 0개
좋아요
댓글(0)
더 이상 게시물에 대한 댓글 기능이 지원되지 않습니다. 자세한 사항은 사이트 소유자에게 문의하세요.
bottom of page


