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 |
Tags
- const l-value참조자
- LAN의 분류
- 프로그래머스 푸드 파이트 대회
- getline()함수
- 백준 파이썬
- IPv4 주소체계
- auto 키워드
- 입출력 관리자
- 문제해결 단계
- 프로그래머스 배열만들기4
- 논리 연산
- 괄호 검사 프로그램
- r-value참조자
- const화
- string유형
- 네트워크 결합
- 범위 기반 for문
- 회전 및 자리 이동 연산
- C언어 덱
- C언어 계산기 프로그램
- 값/참조/주소에 의한 전달
- c언어 괄호검사
- 주기억장치
- 운영체제 기능
- 유형 변환
- 원형 연결 구조 연결된 큐
- C언어 스택 연산
- 알고리즘 조건
- 문자형 배열
- l-value참조자
Archives
- Today
- Total
chyam
[백준] 2178번, python - 미로 탐색 본문

https://www.acmicpc.net/problem/2178
from collections import deque
n, m = map(int,input().split())
miro = []
direct = [[1,0],[-1,0],[0,1],[0,-1]]
for i in range(n):
miro.append(list(map(int,input())))
def bfs(x,y):
queue = deque([(x,y,1)])
visited = [[False] * m for _ in range(n)]
visited[x][y] = True
while queue:
x, y, cnt = queue.popleft()
if x == n-1 and y == m-1: # 끝에 도달 시
return cnt
for dx, dy in direct:
nx, ny = x + dx, y + dy
if 0<= nx < n and 0 <= ny < m and not visited[nx][ny] and miro[nx][ny] == 1:
# 지나갈수있는 길이고 아직 도달하지 않은 곳
visited[nx][ny] = True
queue.append((nx,ny,cnt+1))
print(bfs(0, 0))'백준' 카테고리의 다른 글
| [백준] 1976번,python - 여행 가자 (0) | 2025.09.24 |
|---|---|
| [백준] 14940번,python - 쉬운 최단거리 (0) | 2025.09.23 |
| [백준] 2559번,python - 수열 (0) | 2025.09.19 |
| [백준] 11000번,python - 강의실 배정 (0) | 2025.09.18 |
| [백준] 19941번,python - 햄버거 분배 (0) | 2025.09.17 |