05-21 07:17
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 셀레니움
- Inheritance
- systemd
- Entity
- X.org
- OOP
- X윈도우
- spring
- Physical Scheme
- preprocessing
- 리눅스 마스터 1급
- Entity Set
- Operator
- Unity
- Polymolphism
- BFS
- External Scheme
- literal
- Mac
- Reference Type
- 리눅스
- selenium
- Java
- 자바
- python
- Class
- dbms
- 백준
- descriptive statistics
- Binary Search
Archives
- Today
- Total
Byeol Lo
미로찾기 - bfs 본문
from collections import deque
graph = [
[1,1,1,0,0],
[1,0,1,0,1],
[1,1,1,1,1],
[1,1,0,0,1],
[1,1,1,1,1]
]
dx = [1,-1,0,0]
dy = [0,0,1,-1]
visited = [[False]*5 for _ in range(5)]
path = deque()
def solution(graph, visited, x, y) :
visited[y][x] = True
path = deque([[x, y]])
while path :
x, y = path.popleft()
for i in range(4) :
pos1, pos2 = x+dx[i], y+dy[i]
if 0<=pos1<5 and 0<=pos2<5 and not visited[pos2][pos1] and graph[pos2][pos1] :
visited[pos2][pos1] = visited[y][x]+1
path.append([pos1, pos2])
if __name__=="__main__" :
solution(graph, visited, 0, 0)
for i in visited :
print(*i)
'Programming Language > Python' 카테고리의 다른 글
Python - stable 정렬 (0) | 2022.10.17 |
---|---|
미로찾기 - dfs (0) | 2022.09.02 |
백준 많은 직사각형에 대해 외곽만 그리기 (0) | 2022.08.29 |
Python functools 함수들 (0) | 2022.07.26 |
operator 모듈의 itemgetter, attrgetter 사용하기 (0) | 2022.06.16 |
Comments