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

84-tgyuuAn #261

Merged
merged 1 commit into from
Jan 8, 2025
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
84 changes: 84 additions & 0 deletions tgyuuAn/BFS/뢈!.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import sys

def input(): return sys.stdin.readline().rstrip()

R, C = map(int, input().split())
start = (0, 0)
fire = []

## λ³΄λ“œλ₯Ό λ§Œλ“œλŠ”λ°, κ°€μž₯자리λ₯Ό 도착 지점(*)으둜 감싼닀.
board = [["*" for _ in range(C+2)]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν˜Ήμ‹œ μš”λΆ€λΆ„ κ·Έλƒ₯ λ³΄λ“œ λ²”μœ„λ₯Ό λ²—μ–΄λ‚˜λ„ (r,cκ°€ 0미만, R,C 초과인 경우) 미둜 νƒˆμΆœν–ˆλ‹€λŠ”κ±Έ μ•Œ 수 μžˆμ„ 것 같은데 감싼 μ΄μœ κ°€ μžˆλ‚˜μš”??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν˜Ήμ‹œ μš”λΆ€λΆ„ κ·Έλƒ₯ λ³΄λ“œ λ²”μœ„λ₯Ό λ²—μ–΄λ‚˜λ„ (r,cκ°€ 0미만, R,C 초과인 경우) 미둜 νƒˆμΆœν–ˆλ‹€λŠ”κ±Έ μ•Œ 수 μžˆμ„ 것 같은데 감싼 μ΄μœ κ°€ μžˆλ‚˜μš”??

ν—‰ κ·Έλƒ₯ 더 νŽΈν•˜κ²Œ κ°œλ°œν•˜λ €κ³  κ·Έλž¬μŠ΅λ‹ˆλ‹€!!!!!!

λΆ„κΈ°μ²˜λ¦¬ν•΄μ€˜μ•Ό ν•  것 κ°™μ•„μ„œ ...

for r in range(R):
_input = input()
row = ["*"]
for c, elem in enumerate(_input):
if elem == "J": start = (r+1, c+1)
elif elem == "F": fire.append((r+1, c+1))
row.append(elem)
row.append("*")
board.append(row)
board.append(["*" for _ in range(C+2)])

# for x in board: print(x)
# 뢈이 νΌμ§€λŠ” μœ„μΉ˜λ₯Ό λ¨Όμ € κ³„μ‚°ν•œ ν›„, μ§€ν›ˆμ΄κ°€ 갈 수 μžˆλŠ” μœ„μΉ˜λ₯Ό 계산 함.

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

f = fire[:]
f_visited = set(fire)

j = [start]
j_visited = {start,}

answer = 1
answer_flag = False
while j:
temp_f = []
while f:
(now_r, now_c) = f.pop()

for dire in range(4):
new_r = now_r + dy[dire]
new_c = now_c + dx[dire]

if new_r < 0 or new_r >= R+2: continue
if new_c < 0 or new_c >= C+2: continue
if board[new_r][new_c] == "#": continue
if board[new_r][new_c] == "*": continue
if (new_r, new_c) in f_visited: continue

temp_f.append((new_r, new_c))
f_visited.add((new_r, new_c))

temp_j = []

while j:
(now_r, now_c) = j.pop()

for dire in range(4):
new_r = now_r + dy[dire]
new_c = now_c + dx[dire]

if new_r < 0 or new_r >= R+2: continue
if new_c < 0 or new_c >= C+2: continue
if board[new_r][new_c] == "#": continue
if (new_r, new_c) in j_visited: continue
if (new_r, new_c) in f_visited: continue

if board[new_r][new_c] == "*":
answer_flag = True
print(answer)
break


temp_j.append((new_r, new_c))
j_visited.add((new_r, new_c))

if answer_flag: break
if answer_flag: break
f = temp_f[:]
j = temp_j[:]
answer += 1

else: print("IMPOSSIBLE")
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@
| 81μ°¨μ‹œ | 2024.11.15 | 이뢄 탐색 | <a href="https://www.acmicpc.net/problem/1701">Cubeeditor</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/255
| 82μ°¨μ‹œ | 2024.11.22 | ν¬μ†Œ λ°°μ—΄ | <a href="https://www.acmicpc.net/problem/17435">ν•©μ„±ν•¨μˆ˜μ™€ 쿼리</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/257
| 83μ°¨μ‹œ | 2024.12.01 | μˆ˜ν•™ + κ΅¬ν˜„ | <a href="https://www.acmicpc.net/problem/1033">μΉ΅ν…ŒμΌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/259
| 84μ°¨μ‹œ | 2024.12.31 | BFS | <a href="https://www.acmicpc.net/problem/4179">뢈!</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/261
---
Loading