[20250929] BOJ / G5 / 1로 만들기 2 / 이준희 #998
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/12852
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
숫자가 주어지고 사용할 수 있는 연산은 아래의 3가지 입니다.
이 때 숫자 X를 1로 만드는 최소 연산 횟수를 구하고 그 때 각 연산마다 거치는 숫자를 출력하는 문제입니다.
🔍 풀이 방법
BFS를 이용해서 풀었습니다.
각 3개의 연산을 모두 수행하면서 연산 단계를 진행하였고
X가 1이 되는 경우 BFS를 종료했습니다.
node 에는 현재 수, 연산 횟수, 이전 숫자를 기록하여 거쳐가는 숫자를 관리할 수 있게 하였습니다.
최종적으로는 루트를 역으로 계산해야하므로 리스트에 입력한 후 거꾸로 꺼내면서 출력했습니다.
⏳ 회고
크게 어렵지 않은 BFS 역추적 문제였습니다.