diff --git "a/_WeeklyChallenges/W27-[BFS]/Assignment_BOJ_13549_\354\210\250\353\260\224\352\274\255\354\247\210 3.py" "b/_WeeklyChallenges/W27-[BFS]/Assignment_BOJ_13549_\354\210\250\353\260\224\352\274\255\354\247\210 3.py" new file mode 100644 index 0000000..c3b139c --- /dev/null +++ "b/_WeeklyChallenges/W27-[BFS]/Assignment_BOJ_13549_\354\210\250\353\260\224\352\274\255\354\247\210 3.py" @@ -0,0 +1,31 @@ +from collections import deque +import sys +input = sys.stdin.readline + +def bfs(i,j): + q = deque([i]) + visited[i] = 1 + while q: + x = q.popleft() + if x == j: + return + # !!NOTE!! 2*x, x-1, x+1 순서로 해야함, 그러지 않으면 틀림 + for nx in (2*x, x-1, x+1): + if nx < 0 or nx > MAX: + continue + if visited[nx]: + continue + + if nx == 2*x: + visited[nx] = visited[x] + else: + visited[nx] = visited[x] + 1 + + q.append(nx) + + +N, K = map(int, input().split()) +MAX = 10**5 +visited = [0] * (MAX+1) +bfs(N,K) +print(visited[K]-1) \ No newline at end of file diff --git a/_WeeklyChallenges/W27-[BFS]/README.md b/_WeeklyChallenges/W27-[BFS]/README.md new file mode 100644 index 0000000..0cde948 --- /dev/null +++ b/_WeeklyChallenges/W27-[BFS]/README.md @@ -0,0 +1,16 @@ +## 🚀6월 3주차 (6/16) 스터디 발제 주제: BFS +> 발제자: 조윤상 (@YoonYn9915) + +> [!NOTE] +> 주제: BFS + +### 🗂️ 스터디 자료 +- PDF: [바로가기](Study_BOJ_14226.pdf) + +### 📖 문제 +- [백준 #이모티콘](https://www.acmicpc.net/problem/14226): BFS / 골드 5 +- 정답 코드: [Study_BOJ_14226_이모티콘.py](Study_BOJ_14226_이모티콘.py) + +### 💻 과제 +- [백준 #숨바꼭질 3](https://www.acmicpc.net/problem/13549): BFS / 골드 4 +- 정답 코드: [Assignment_BOJ_13549_숨바꼭질 3.py](Assignment_BOJ_13549_숨바꼭질 3.py) diff --git a/_WeeklyChallenges/W27-[BFS]/Study_BOJ_14226.pdf b/_WeeklyChallenges/W27-[BFS]/Study_BOJ_14226.pdf new file mode 100644 index 0000000..f3ab175 Binary files /dev/null and b/_WeeklyChallenges/W27-[BFS]/Study_BOJ_14226.pdf differ diff --git "a/_WeeklyChallenges/W27-[BFS]/Study_BOJ_14226_\354\235\264\353\252\250\355\213\260\354\275\230.py" "b/_WeeklyChallenges/W27-[BFS]/Study_BOJ_14226_\354\235\264\353\252\250\355\213\260\354\275\230.py" new file mode 100644 index 0000000..0a0b1bc --- /dev/null +++ "b/_WeeklyChallenges/W27-[BFS]/Study_BOJ_14226_\354\235\264\353\252\250\355\213\260\354\275\230.py" @@ -0,0 +1,34 @@ +from collections import deque +import sys + +S = int(sys.stdin.readline().strip()) + +# visited[screen][clipboard] +visited = [[-1] * (S + 1) for _ in range(S + 1)] + +queue = deque() +queue.append((1, 0)) # 화면: 1, 클립보드: 0 +visited[1][0] = 0 + +while queue: + screen, clipboard = queue.popleft() + + # 목표 이모티콘 수에 도달하면 종료 + if screen == S: + print(visited[screen][clipboard]) + break + + # 1. 복사 (화면 -> 클립보드) + if visited[screen][screen] == -1: + visited[screen][screen] = visited[screen][clipboard] + 1 + queue.append((screen, screen)) + + # 2. 붙여넣기 (클립보드 -> 화면) + if clipboard != 0 and screen + clipboard <= S and visited[screen + clipboard][clipboard] == -1: + visited[screen + clipboard][clipboard] = visited[screen][clipboard] + 1 + queue.append((screen + clipboard, clipboard)) + + # 3. 삭제 (화면 -1) + if screen - 1 >= 0 and visited[screen - 1][clipboard] == -1: + visited[screen - 1][clipboard] = visited[screen][clipboard] + 1 + queue.append((screen - 1, clipboard)) diff --git "a/_WeeklyChallenges/W27-[PriorityQueue]/Assignment_PGS_42628_\341\204\213\341\205\265\341\204\214\341\205\256\341\206\274\341\204\213\341\205\256\341\204\211\341\205\245\341\206\253\341\204\211\341\205\256\341\206\253\341\204\213\341\205\261\341\204\217\341\205\262.py" "b/_WeeklyChallenges/W29-[PriorityQueue]/Assignment_PGS_42628_\341\204\213\341\205\265\341\204\214\341\205\256\341\206\274\341\204\213\341\205\256\341\204\211\341\205\245\341\206\253\341\204\211\341\205\256\341\206\253\341\204\213\341\205\261\341\204\217\341\205\262.py" similarity index 100% rename from "_WeeklyChallenges/W27-[PriorityQueue]/Assignment_PGS_42628_\341\204\213\341\205\265\341\204\214\341\205\256\341\206\274\341\204\213\341\205\256\341\204\211\341\205\245\341\206\253\341\204\211\341\205\256\341\206\253\341\204\213\341\205\261\341\204\217\341\205\262.py" rename to "_WeeklyChallenges/W29-[PriorityQueue]/Assignment_PGS_42628_\341\204\213\341\205\265\341\204\214\341\205\256\341\206\274\341\204\213\341\205\256\341\204\211\341\205\245\341\206\253\341\204\211\341\205\256\341\206\253\341\204\213\341\205\261\341\204\217\341\205\262.py" diff --git a/_WeeklyChallenges/W27-[PriorityQueue]/README.md b/_WeeklyChallenges/W29-[PriorityQueue]/README.md similarity index 100% rename from _WeeklyChallenges/W27-[PriorityQueue]/README.md rename to _WeeklyChallenges/W29-[PriorityQueue]/README.md diff --git a/_WeeklyChallenges/W27-[PriorityQueue]/Study_PGS_42627.pdf b/_WeeklyChallenges/W29-[PriorityQueue]/Study_PGS_42627.pdf similarity index 100% rename from _WeeklyChallenges/W27-[PriorityQueue]/Study_PGS_42627.pdf rename to _WeeklyChallenges/W29-[PriorityQueue]/Study_PGS_42627.pdf diff --git "a/_WeeklyChallenges/W27-[PriorityQueue]/Study_PGS_42627_\341\204\203\341\205\265\341\204\211\341\205\263\341\204\217\341\205\263\341\204\217\341\205\245\341\206\253\341\204\220\341\205\263\341\204\205\341\205\251\341\206\257\341\204\205\341\205\245.py" "b/_WeeklyChallenges/W29-[PriorityQueue]/Study_PGS_42627_\341\204\203\341\205\265\341\204\211\341\205\263\341\204\217\341\205\263\341\204\217\341\205\245\341\206\253\341\204\220\341\205\263\341\204\205\341\205\251\341\206\257\341\204\205\341\205\245.py" similarity index 100% rename from "_WeeklyChallenges/W27-[PriorityQueue]/Study_PGS_42627_\341\204\203\341\205\265\341\204\211\341\205\263\341\204\217\341\205\263\341\204\217\341\205\245\341\206\253\341\204\220\341\205\263\341\204\205\341\205\251\341\206\257\341\204\205\341\205\245.py" rename to "_WeeklyChallenges/W29-[PriorityQueue]/Study_PGS_42627_\341\204\203\341\205\265\341\204\211\341\205\263\341\204\217\341\205\263\341\204\217\341\205\245\341\206\253\341\204\220\341\205\263\341\204\205\341\205\251\341\206\257\341\204\205\341\205\245.py"