1226. 미로1
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
- 내 풀이
# 0: 길 1: 벽
# 시작점 1,1
from collections import deque
def bfs(i,j):
visited[i][j]=True
queue.append((i,j))
while queue:
x,y=queue.popleft()
for i in range(4):
nx=x+dx[i]
ny=y+dy[i]
if 1<=nx<15 and 1<=ny<15 and graph[nx][ny]!=1 and visited[nx][ny]==False:
visited[nx][ny]=True;
queue.append((nx,ny))
for _ in range(10):
tc=int(input())
graph=[list(map(int,input().rstrip())) for _ in range(16)]
dx=[-1,1,0,0]
dy=[0,0,-1,1]
queue=deque()
visited=[[False for _ in range(16)] for _ in range(16)]
for i in range(16):
for j in range(16):
if graph[i][j]==2:
bfs(i,j)
elif graph[i][j]==3:
endX=i
endY=j
result=0
if visited[endX][endY]==True:
result=1
print(f'#{tc} {result}')'코딩테스트 > SWEA' 카테고리의 다른 글
| [SWEA] 2105. 디저트 카페 (0) | 2023.05.22 |
|---|---|
| [SWEA] [부분집합] [백트래킹] 5215. 햄버거 다이어트 (0) | 2023.04.10 |
| [SW] 1247. 최적 경로 (0) | 2023.02.23 |
| [SW4008][DFS] 숫자 만들기 (0) | 2023.02.15 |
| [SW 1233][tree] 사칙 연산 유효성 검사 (0) | 2023.02.14 |