Skip to content

Commit

Permalink
2024-08-17
Browse files Browse the repository at this point in the history
  • Loading branch information
H0ngJu committed Aug 17, 2024
1 parent bd62d9a commit 03a308d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
64 changes: 64 additions & 0 deletions H0ngJu/BFS/์•„๊ธฐ์ƒ์–ด.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import sys
from collections import deque

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

N = int(input())
space = [list(map(int, input().split())) for _ in range(N)]

dir = [(0,1), (0,-1), (1,0), (-1,0)]
x = 0
y = 0

for i in range(N):
for j in range(N):
if space[i][j] == 9:
x, y = i, j
space[x][y] = 0

def check(a, b):
if 0<=a<N and 0<=b<N:
return True
return False

baby = 2

time = 0
fish = 0

while True:
q = deque([(x, y, 0)])
visited = [[False] * N for _ in range(N)]
visited[x][y] = True
min_dis = float('inf')
tmp = []

while q:
cx, cy, dis = q.popleft()

if 0 < space[cx][cy] < baby:
if dis < min_dis:
min_dis = dis
tmp = [(cx, cy)]
elif dis == min_dis:
tmp.append((cx, cy))

for dx, dy in dir:
nx, ny = cx + dx, cy + dy
if check(nx, ny) and not visited[nx][ny] and space[nx][ny] <= baby:
visited[nx][ny] = True
q.append((nx, ny, dis + 1))

if not tmp:
break

tx, ty = min(tmp)
space[tx][ty] = 0
time += min_dis
fish += 1
if fish == baby:
baby += 1
fish = 0
x, y = tx, ty

print(time)
2 changes: 1 addition & 1 deletion H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
| 20์ฐจ์‹œ | 2024.06.03 | ๋ฐฑํŠธ๋ž˜ํ‚น | [์Šคํƒ€ํŠธ์™€ ๋งํฌ](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/206 |
| 21์ฐจ์‹œ | 2024.06.07 | ๊ทธ๋ฆฌ๋”” | [ํ–‰๋ณต ์œ ์น˜์›](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 |

| 24์ฐจ์‹œ | 2024.08.12 | BFS | [๋งฅ์ฃผ ๋งˆ์‹œ๋ฉด์„œ ๊ฑธ์–ด๊ฐ€๊ธฐ](https://www.acmicpc.net/problem/9205) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/229 |
| 24์ฐจ์‹œ | 2024.08.17 | BFS | [์•„๊ธฐ์ƒ์–ด](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 |

---

0 comments on commit 03a308d

Please sign in to comment.