728x90
SMALL
어제 풀다가 대체 왜 틀린지 모른상태로 오늘 밤부터 다시 풀었는데....
현타왔다..
dx = currentX + direction[i][0]
dy = currentY + direction[i][1]
이부분이
dx = currentX = direction[i][0]
dy = currentY = direction[i][1]
이렇게 돼있었는데 그걸 발견을 못 했다....
ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
진짜 어이없는 실수해서 시간 잡아먹을 때가 너무 속상하다 ㅠㅠ 😓
from collections import deque
testCase = int(input())
direction = [(-2,-1),(-1,-2),(1,-2),(2,-1),(-2,1),(-1,2),(1,2),(2,1)]
def bfs(nowX,nowY,nextX,nextY,idx):
queue = deque()
queue.append((nowX,nowY))
result[nowX][nowY] = 1
if nowX == nextX and nowY == nextY:
answer[idx]=0
while queue:
currentX,currentY = queue.popleft()
if currentX == nextX and currentY == nextY:
answer[idx]=result[currentX][currentY]-1
break
for i in range(8):
dx = currentX + direction[i][0]
dy = currentY + direction[i][1]
if 0<= dx <length and 0<=dy<length :
if result[dx][dy] == 0:
queue.append((dx, dy))
result[dx][dy] = result[currentX][currentY]+1
answer = [0]*testCase
for i in range(testCase):
length = int(input())
now_x,now_y = map(int,input().split())
next_x,next_y = map(int,input().split())
result = [[0] * length for _ in range(length)]
bfs(now_x,now_y,next_x,next_y,i)
for i in answer:
print(i)
728x90
LIST
'취준시절 > 백준' 카테고리의 다른 글
[백준 10026] 적록색약 - Python (0) | 2021.07.01 |
---|---|
[백준 11724] 연결 요소의 개수 - Python (0) | 2021.07.01 |
[백준 2606] 바이러스 - Python (0) | 2021.07.01 |
[백준 2644] 촌수계산 - Python (0) | 2021.06.29 |
[백준 4963] 섬의개수 - Python (0) | 2021.06.28 |