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 |
31 |
Tags
- Module
- Rtl
- HDL
- boj
- 알고리즘
- 비트마스킹
- 모듈
- dfs연습문제
- DFS
- verilogHDL
- 모델링
- verilog HDL
- 감시
- HWEngineer
- 15683
- 14889
- verilog
- HW
- 가속기시스템
- 백준
- testbench
- 비트마스크알고리즘
- 최적화
- 가속컴퓨팅
- RTLEngineer
- 스타트와링크
- 코딩테스트
- 비트마스크
Archives
- Today
- Total
oohyoo 님의 블로그
[Python] 프로그래머스 - 미로 탐험1 본문
[문제]
[풀이]
#입력과 출력을 자유롭게 작성해주세요
from collections import deque
def solution(H, W, h, w, house):
queue = deque()
dh = [-1, 0, 1, 0]
dw = [0, 1, 0, -1]
visited = [[False]*W for _ in range(H)]
queue.append((h, w, 0))
while queue:
x, y, dist = queue.popleft()
for d in range(4):
cx = x+dh[d]
cy = y+dw[d]
if(0<=cx<H and 0<=cy<W and house[cx][cy] !=0 and not visited[cx][cy]):
visited[cx][cy] = True
queue.append((cx, cy, dist+1))
house[cx][cy] = dist+1
for i in range(H):
for j in range(W):
if not visited[i][j]:
print(0, end=' ')
elif (i == h and j == w):
print(0, end=' ')
else:
print(str(house[i][j]), end=' ')
print()
H, W = map(int, input().split())
house = []
for th in range(H):
temp = list(map(int, input().strip()))
if 2 in temp:
h = th
w = temp.index(2)
house.append(temp)
solution(H, W, h, w, house)
반응형
'코딩테스트' 카테고리의 다른 글
[Python] 프로그래머스 - 미로 탐험2 (0) | 2025.02.03 |
---|---|
[Python] 프로그래머스 - 가장 빠른 거리 (0) | 2025.02.03 |
[Python] 프로그래머스 - 외톨이 알파벳 (1) | 2025.02.03 |
[Python] 프로그래머스 Sort 교육자료 (0) | 2025.02.03 |
[Python] 프로그래머스 Set 강의자료 (0) | 2025.02.03 |