diff --git "a/H0ngJu/BFS/\354\210\250\353\260\224\352\274\255\354\247\2104.py" "b/H0ngJu/BFS/\354\210\250\353\260\224\352\274\255\354\247\2104.py" new file mode 100644 index 00000000..d1db02cf --- /dev/null +++ "b/H0ngJu/BFS/\354\210\250\353\260\224\352\274\255\354\247\2104.py" @@ -0,0 +1,33 @@ +import sys +from collections import deque + +def input(): return sys.stdin.readline() + +N, K = map(int, input().split()) + +visited = [0] * 100001 +time = 0 +parent = [-1] * 100001 + +q = deque([N]) +visited[N] = 1 + +while q: + size = len(q) + for _ in range(size): + location = q.popleft() + if location == K: + print(time) + answer = [] + while location != -1: + answer.append(location) + location = parent[location] + answer.reverse() + print(" ".join(map(str, answer))) + break + for next_location in (location + 1, location - 1, location * 2): + if 0 <= next_location <= 100000 and not visited[next_location]: + q.append(next_location) + visited[next_location] = 1 + parent[next_location] = location + time += 1 diff --git a/H0ngJu/README.md b/H0ngJu/README.md index eea8f055..28f281eb 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -1,13 +1,14 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | -| 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | -| 2차시 | 2024.03.07 | 큐 | [다리를 지나는 트럭](https://school.programmers.co.kr/learn/courses/30/lessons/42583) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153 | -| 3차시 | 2024.03.10 | 힙 | [N번째 큰 수](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 | -| 4차시 | 2024.03.13 | 힙 | [문제집](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 | -| 5차시 | 2024.03.16 | 구현 | [요세푸스 문제](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 | -| 6차시 | 2024.03.19 | 스택 | [오큰수](https://www.acmicpc.net/problem/17298) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/164 | -| 7차시 | 2024.03.22 | DP | [1,2,3 더하기](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/166 | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +| :----: | :--------: | :------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------: | +| 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | +| 2차시 | 2024.03.07 | 큐 | [다리를 지나는 트럭](https://school.programmers.co.kr/learn/courses/30/lessons/42583) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153 | +| 3차시 | 2024.03.10 | 힙 | [N번째 큰 수](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 | +| 4차시 | 2024.03.13 | 힙 | [문제집](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 | +| 5차시 | 2024.03.16 | 구현 | [요세푸스 문제](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 | +| 6차시 | 2024.03.19 | 스택 | [오큰수](https://www.acmicpc.net/problem/17298) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/164 | +| 7차시 | 2024.03.22 | DP | [1,2,3 더하기](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/166 | +| 10차시 | 2024.04.03 | BFS | [숨바꼭질 4](https://www.acmicpc.net/problem/13913) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/177 | ---