Skip to content

Commit

Permalink
2024-12-31
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Dec 31, 2024
1 parent 00438a2 commit ac24a14
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
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)]]
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
---

0 comments on commit ac24a14

Please sign in to comment.