Notice
Recent Posts
Recent Comments
Link
나의 개발일지
[백준] 16173 점프왕 쩰리(Small) [Python, 파이썬] 본문
- 문제 : https://www.acmicpc.net/problem/16173
- BFS
- 한 칸씩 이동이 아닌 현재 위치에 적혀있는 숫자만큼 이동을 시키는 문제 (오른쪽, 아래로만)
from collections import deque
n = int(input())
Map = [list(map(int, input().split())) for _ in range(n)]
visit = [[0] * n for _ in range(n)]
visit[0][0] = 1
q = deque([(0, 0)])
while q:
x, y = q.popleft()
mx, my = [0, Map[x][y]], [Map[x][y], 0] # 현재 위치에 적힌 숫자만큼 이동
if x == n-1 and y == n-1:
print("HaruHaru")
exit()
for i in range(2):
nx, ny = x + mx[i], y + my[i]
if 0 <= nx < n and 0 <= ny < n and visit[nx][ny] == 0:
q.append((nx, ny))
visit[nx][ny] = 1
print("Hing")
'백준' 카테고리의 다른 글
[백준] 26169 세 번 이내에 사과를 먹자 [Python, 파이썬] (0) | 2023.09.15 |
---|---|
[백준] 1388 바닥 장식 [Python, 파이썬] (0) | 2023.09.14 |
[공식] 조합 공식, 순열 공식 (0) | 2023.09.11 |
[백준] 17202 핸드폰 번호 궁합 [Python, 파이썬] (0) | 2023.09.11 |
[백준] 24416 알고리즘 수업 - 피보나치 수 1 [Python, 파이썬] (0) | 2023.09.11 |
Comments