Skip to content

Commit 7e1378b

Browse files
authored
Merge pull request #210 from AlgorithmStudy-Allumbus/mj/presentation
πŸš€5μ›” 3μ£Όμ°¨ (5/19) μŠ€ν„°λ”” 발제 자료 μ—…λ‘œλ“œ
2 parents 7a12ae7 + af78c31 commit 7e1378b

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""
2+
BOJ #7569. ν† λ§ˆν†  (3차원) (κ³¨λ“œ5)
3+
https://www.acmicpc.net/problem/7569
4+
μœ ν˜•: Graph, BFS
5+
"""
6+
# PR 올릴 λ•Œ 곡개 μ˜ˆμ •
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## πŸš€5μ›” 3μ£Όμ°¨ (5/19) μŠ€ν„°λ”” 발제 주제: Graph (BFS)
2+
> 발제자: κΉ€λ―Όμ • (@Mingguriguri)
3+
4+
> [!NOTE]
5+
> 주제: Graph (BFS)
6+
7+
### πŸ—‚οΈ μŠ€ν„°λ”” 자료
8+
- PDF: [λ°”λ‘œκ°€κΈ°](Study_BOJ_7576.pdf)
9+
<img width="500" alt="μŠ€ν„°λ””λ¬Έμ œ" src="https://github.com/user-attachments/assets/5ef6096c-b265-4595-8a0e-033905fc2ea6" />
10+
<img width="500" alt="발제문제" src="https://github.com/user-attachments/assets/c4495d0b-0c96-4bd3-bcd5-a40be6c99f4e" />
11+
12+
### πŸ“– 문제
13+
- [λ°±μ€€ #7576. ν† λ§ˆν† ](https://www.acmicpc.net/problem/7576): Graph (BFS) / κ³¨λ“œ5
14+
- μ •λ‹΅ μ½”λ“œ: [Study_BOJ_7576_ν† λ§ˆν† .py](Study_BOJ_7576_ν† λ§ˆν† .py)
15+
16+
### πŸ’» 과제
17+
- [λ°±μ€€ #7569. ν† λ§ˆν† ](https://www.acmicpc.net/problem/7569): Graph (BFS) / κ³¨λ“œ5
18+
- μ •λ‹΅ μ½”λ“œ: [Assignment_BOJ_7569_ν† λ§ˆν† .py](Assignment_BOJ_7569_ν† λ§ˆν† .py)
530 KB
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
BOJ #7576. ν† λ§ˆν†  (2차원) (κ³¨λ“œ5)
3+
https://www.acmicpc.net/problem/7576
4+
μœ ν˜•: Graph, BFS
5+
"""
6+
import sys
7+
from collections import deque
8+
input = sys.stdin.readline
9+
10+
# 1. μž…λ ₯ 처리
11+
M, N = map(int, input().split()) # κ°€λ‘œ μΉΈ 수, μ„Έλ‘œ μΉΈ 수
12+
box = [list(map(int, input().split())) for _ in range(N)] # ν† λ§ˆν† 
13+
14+
# 2. 초기 μ„€μ •
15+
queue = deque([]) # 큐
16+
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)] # λ°©ν–₯벑터
17+
day = 0 # 정닡이 λ‹΄κΈΈ λ³€μˆ˜
18+
19+
# 3. 큐에 초기 읡은 ν† λ§ˆν†  μœ„μΉ˜ μ €μž₯
20+
for i in range(N):
21+
for j in range(M):
22+
if box[i][j] == 1:
23+
queue.append((i, j))
24+
25+
# 4. BFS 탐색
26+
while queue:
27+
# 처음 ν† λ§ˆν†  κΊΌλ‚΄κΈ°
28+
x, y = queue.popleft()
29+
30+
# 처음 ν† λ§ˆν† μ˜ μΈμ ‘ν•œ ν† λ§ˆν†  μ°ΎκΈ°
31+
for dx, dy in directions:
32+
nx, ny = x + dx, y + dy
33+
34+
# λ²”μœ„ 내에 있고, ν† λ§ˆν† κ°€ 읡지 μ•Šμ€ 경우
35+
if (0 <= nx < N and 0 <= ny < M) and (box[nx][ny] == 0):
36+
# 읡히고 1 더해주며 횟수 μ„ΈκΈ°
37+
# μ—¬κΈ°μ„œ λ‚˜μ˜¨ 제일 큰 값이 정닡이 λœλ‹€.
38+
box[nx][ny] += box[x][y] + 1 # 일수 λˆ„μ 
39+
queue.append((nx, ny))
40+
41+
42+
# 5. μ •λ‹΅ κ΅¬ν•˜κΈ°
43+
for row in box:
44+
for tomato in row:
45+
# λͺ¨λ‘ νƒμƒ‰ν–ˆμ§€λ§Œ ν† λ§ˆν† κ°€ λͺ¨λ‘ 읡지 μ•Šμ•˜λ‹€λ©΄ -1 좜λ ₯
46+
if tomato == 0:
47+
print(-1)
48+
exit()
49+
50+
# λ‹€ μ΅ν˜”λ‹€λ©΄ μ΅œλŒ“κ°’μ΄ μ •λ‹΅
51+
day = max(day, max(row))
52+
53+
# 6. μ •λ‹΅ 좜λ ₯
54+
print(day - 1) # μ²˜μŒμ— 1둜 읡은 ν† λ§ˆν† λ₯Ό ν‘œν˜„ν–ˆμœΌλ‹ˆ 1을 λΉΌμ€€λ‹€.

0 commit comments

Comments
Β (0)