Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20-LJEDD2 #80

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions LJEDD2/BFS/상범 λΉŒλ”©.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# μ •μœ‘λ©΄μ²΄
# 금으둜 이뀄진 뢀뢄은 μ§€λ‚˜κ°ˆ 수 μ—†λ‹€.
# 이동 κ°€λŠ₯ λ²”μœ„ - 동 μ„œ 남 뢁 상 ν•˜ - 6 λ°©ν–₯
# λŒ€κ°μ„  X

from collections import deque

# 3μ°¨μ›μ—μ„œμ˜ 이동을 λ‚˜νƒ€λ‚΄μ•Ό 함.

# 제자리 - 동 μ„œ 남 뢁
# 상 - 동 μ„œ 남 뢁 # ν•˜ - 동 μ„œ 남 뢁
offset = [(1,0,0),(-1,0,0),(0,-1,0),(0,1,0),(0,0,-1),(0,0,1)]

# κ·Έλž˜ν”„ λ²”μœ„ λ‚΄ 체크
def OOB(floor,x,y):
return not(0 <= floor < L and 0 <= x < R and 0 <= y < C)

# λ„ˆλΉ„ 탐색 μ•Œκ³ λ¦¬μ¦˜
def bfs(sl,sr,sc):
visited = [[[0] * C for _ in range(R)] for _ in range(L)]
visited[sl][sr][sc] = 1

queue = deque([(sl,sr,sc)])

while queue:
# f = floorλ₯Ό 의미
f, x, y = queue.popleft()

for df, dx, dy in offset:
nf, nx, ny = f + df, x + dx, y + dy

if not OOB(nf,nx,ny) and not visited[nf][nx][ny] and building[nf][nx][ny] != '#':
# νƒˆμΆœ 지점일 경우 μ†Œμš” μ‹œκ°„ 리턴
if building[nf][nx][ny] == 'E':
return visited[f][x][y]

visited[nf][nx][ny] = visited[f][x][y] + 1
queue.append((nf,nx,ny))
return None

# 주어진 λΉŒλ”© ꡬ쑰와 좜발점 정보λ₯Ό 기반으둜 νƒˆμΆœ κ°€λŠ₯ μ—¬λΆ€λ₯Ό νŒλ‹¨
def solve(L, R, C):
global building
building = []

for l in range(L):
building.append([list(input().rstrip()) for _ in range(R)])
for r in range(R):
for c in range(C):
if building[l][r][c] == "S":
sl, sr, sc = l, r, c
input()

# μ΅œμ†Œ μ†Œμš” μ‹œκ°„ 계산
time = bfs(sl,sr,sc)

if time:
return print(f"Escaped in {time} minute(s).")
else:
return print('Trapped!')

# MAIN
while True:
L,R,C = map(int,input().split())

if not L and not R and not C :
break

# 각 μΌ€μ΄μŠ€λ³„ μ†Œμš”μ‹œκ°„μ„ 리턴
solve(L, R, C)
2 changes: 1 addition & 1 deletion LJEDD2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
| 17μ°¨μ‹œ | 2024.02.18 | λΆ„ν•  정볡 | <a href="https://www.acmicpc.net/problem/4779">μΉΈν† μ–΄ 집합</a> | [#70](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/70) |
| 18μ°¨μ‹œ | 2024.02.21 | λΆ„ν•  정볡 | <a href="https://www.acmicpc.net/problem/1780">μ’…μ΄μ˜ 개수</a> | [#73](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/73) |
| 19μ°¨μ‹œ | 2024.02.24 | κ΅¬ν˜„ | <a href="https://www.acmicpc.net/problem/16919">봄버맨 2</a> | [#76](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/76) |

| 20μ°¨μ‹œ | 2024.02.27 | BFS | <a href="https://www.acmicpc.net/problem/6593">상범 λΉŒλ”© 2</a> | [#80](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/80) |
---