From bc9939fdb65eb9080093085ec74584e472c65b15 Mon Sep 17 00:00:00 2001 From: JSPark <48265129+pknujsp@users.noreply.github.com> Date: Sun, 4 Feb 2024 23:08:38 +0900 Subject: [PATCH] 2024-02-04 --- ...\353\260\224\352\274\255\354\247\210 3.py" | 31 +++++++++++++++++++ pknujsp/README.md | 3 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 "pknujsp/BFS/32-\354\210\250\353\260\224\352\274\255\354\247\210 3.py" diff --git "a/pknujsp/BFS/32-\354\210\250\353\260\224\352\274\255\354\247\210 3.py" "b/pknujsp/BFS/32-\354\210\250\353\260\224\352\274\255\354\247\210 3.py" new file mode 100644 index 00000000..e6aa58f5 --- /dev/null +++ "b/pknujsp/BFS/32-\354\210\250\353\260\224\352\274\255\354\247\210 3.py" @@ -0,0 +1,31 @@ +from sys import * +from collections import * + +n, k = map(int, stdin.readline().strip().split()) + +max_idx = 100001 + +q = deque([(n, 0)]) +visited = [False] * max_idx +visited[n] = True + +while q: + x, cost = q.popleft() + if x == k: + print(cost) + break + + nx = x + x + if nx < max_idx and not visited[nx]: + visited[nx] = True + q.appendleft((nx, cost)) + + nx = x - 1 + if 0 <= nx and not visited[nx]: + visited[nx] = True + q.append((nx, cost + 1)) + + nx = x + 1 + if nx < max_idx and not visited[nx]: + visited[nx] = True + q.append((nx, cost + 1)) diff --git a/pknujsp/README.md b/pknujsp/README.md index bdb6a818..d8568f58 100644 --- a/pknujsp/README.md +++ b/pknujsp/README.md @@ -32,4 +32,5 @@ | 28차시 | 2024.01.16 | 그리디 | [무지의 먹방 라이브](https://school.programmers.co.kr/learn/courses/30/lessons/42891) | [#110](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/110) | | 29차시 | 2024.01.18 | DFS, UNION-FIND | [순열 사이클](https://www.acmicpc.net/problem/10451) | [#112](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/112) | | 30차시 | 2024.01.23 | DP | [ABBC](https://www.acmicpc.net/problem/25381) | [#119](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/119) | -| 31차시 | 2024.01.30 | SORT | [멀티버스 Ⅱ](https://www.acmicpc.net/problem/18869) | [#123](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/123) | \ No newline at end of file +| 31차시 | 2024.01.30 | SORT | [멀티버스 Ⅱ](https://www.acmicpc.net/problem/18869) | [#123](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/123) | +| 32차시 | 2024.02.04 | BFS | [숨바꼭질 3](https://www.acmicpc.net/problem/13549) | [#127](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/127) | \ No newline at end of file