Skip to content

Commit f72e9b1

Browse files
committed
feat: 6월 3주차 과제 문제 풀이 업로드
1 parent 6ea0587 commit f72e9b1

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from collections import deque
2+
import sys
3+
input = sys.stdin.readline
4+
5+
def bfs(i,j):
6+
q = deque([i])
7+
visited[i] = 1
8+
while q:
9+
x = q.popleft()
10+
if x == j:
11+
return
12+
# !!NOTE!! 2*x, x-1, x+1 순서로 해야함, 그러지 않으면 틀림
13+
for nx in (2*x, x-1, x+1):
14+
if nx < 0 or nx > MAX:
15+
continue
16+
if visited[nx]:
17+
continue
18+
19+
if nx == 2*x:
20+
visited[nx] = visited[x]
21+
else:
22+
visited[nx] = visited[x] + 1
23+
24+
q.append(nx)
25+
26+
27+
N, K = map(int, input().split())
28+
MAX = 10**5
29+
visited = [0] * (MAX+1)
30+
bfs(N,K)
31+
print(visited[K]-1)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## 🚀6월 3주차 (6/16) 스터디 발제 주제: BFS
2+
> 발제자: 조윤상 (@Mingguriguri)
3+
4+
> [!NOTE]
5+
> 주제: BFS
6+
7+
### 🗂️ 스터디 자료
8+
- PDF: [바로가기](Study_BOJ_14226.pdf)
9+
10+
### 📖 문제
11+
- [백준 #이모티콘](https://www.acmicpc.net/problem/14226): BFS / 골드 5
12+
- 정답 코드: [Study_BOJ_14226_이모티콘.py](Study_BOJ_14226_이모티콘.py)
13+
14+
### 💻 과제
15+
- [백준 #숨바꼭질 3](https://www.acmicpc.net/problem/13549): BFS / 골드 4
16+
- 정답 코드: [Assignment_BOJ_13549_숨바꼭질 3.py](Assignment_BOJ_13549_숨바꼭질 3.py)
372 KB
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from collections import deque
2+
import sys
3+
4+
S = int(sys.stdin.readline().strip())
5+
6+
# visited[screen][clipboard]
7+
visited = [[-1] * (S + 1) for _ in range(S + 1)]
8+
9+
queue = deque()
10+
queue.append((1, 0)) # 화면: 1, 클립보드: 0
11+
visited[1][0] = 0
12+
13+
while queue:
14+
screen, clipboard = queue.popleft()
15+
16+
# 목표 이모티콘 수에 도달하면 종료
17+
if screen == S:
18+
print(visited[screen][clipboard])
19+
break
20+
21+
# 1. 복사 (화면 -> 클립보드)
22+
if visited[screen][screen] == -1:
23+
visited[screen][screen] = visited[screen][clipboard] + 1
24+
queue.append((screen, screen))
25+
26+
# 2. 붙여넣기 (클립보드 -> 화면)
27+
if clipboard != 0 and screen + clipboard <= S and visited[screen + clipboard][clipboard] == -1:
28+
visited[screen + clipboard][clipboard] = visited[screen][clipboard] + 1
29+
queue.append((screen + clipboard, clipboard))
30+
31+
# 3. 삭제 (화면 -1)
32+
if screen - 1 >= 0 and visited[screen - 1][clipboard] == -1:
33+
visited[screen - 1][clipboard] = visited[screen][clipboard] + 1
34+
queue.append((screen - 1, clipboard))

0 commit comments

Comments
 (0)