Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 삼성소프트웨어
- MSSQL
- minmax
- 단지번호붙이기
- 이코테
- dfs
- pep8
- 2178
- 파이썬컨벤션
- WebMvcConfigurer
- 2667
- BFS
- setviewname
- 미로탈출
- React
- __name__
- Arecode
- 화살표함수
- Spring
- SWEA
- 백준
- 2606
- 파이썬스럽게
- addAttribute
- 우선순위큐
- 음료수얼려먹기
- major gc
- JWT
- heapq
- 미로탐색
Archives
- Today
- Total
하루하루는 성실하게 인생 전체는 되는대로
[백준] 2178 - 미로 탐색 본문
from collections import deque
n, m = map(int, input().split())
graph = [list(map(int, input())) for i in range(n)]
def bfs(x,y):
que = deque()
que.append((x, y))
while que:
x, y = que.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if nx<=-1 or nx>=n or ny<=-1 or ny>=m:
continue
if graph[nx][ny]==0:
continue
if graph[nx][ny]==1:
graph[nx][ny]=graph[x][y]+1
que.append((nx, ny))
dx = [-1,1,0,0]
dy = [0,0,-1,1]
bfs(0,0)
print(graph[n-1][m-1])
- 풀이 평가 : 30분 내에 풀이 완료! 저번에 풀었던 거랑 거의 똑같아서 크게 어려움은 없었음
- 풀이 핵심 아이디어 : 이전 값을 현재 값에 더해주기 위해, for문(현재 노드 시작되는 영역) 상에서 모든 것을 전개했다.
'알고리즘 Archive' 카테고리의 다른 글
[백준] 1697 - 숨바꼭질 (0) | 2021.03.24 |
---|---|
[백준] 2606 - 바이러스 (0) | 2021.03.24 |
[백준] 2667 - 단지번호붙이기 (0) | 2021.03.24 |
[백준] 1260 - dfs와 bfs (미완-다시풀기) (0) | 2021.03.24 |
BFS - 미로 탈출 (0) | 2021.03.24 |
Comments