File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ a ,b = map (int ,input ().split ())
2+ cnt = 1
3+ while (b != a ):
4+ cnt += 1
5+ temp = b
6+ if b % 10 == 1 : b //= 10
7+ elif b % 2 == 0 : b //= 2
8+
9+ if temp == b :
10+ print (- 1 )
11+ break
12+ else :
13+ print (cnt )
Original file line number Diff line number Diff line change 1+ # [ Silver II] A → B - 16953
2+
3+ [ 문제 링크] ( https://www.acmicpc.net/problem/16953 )
4+
5+ ### 성능 요약
6+
7+ 메모리: 108080 KB, 시간: 112 ms
8+
9+ ### 분류
10+
11+ 너비 우선 탐색, 그래프 이론, 그래프 탐색, 그리디 알고리즘
12+
13+ ### 제출 일자
14+
15+ 2024년 4월 11일 15:10:26
16+
17+ ### 문제 설명
18+
19+ <p >정수 A를 B로 바꾸려고 한다. 가능한 연산은 다음과 같은 두 가지이다.</p >
20+
21+ <ul >
22+ <li>2를 곱한다.</li>
23+ <li>1을 수의 가장 오른쪽에 추가한다. </li>
24+ </ul >
25+
26+ <p >A를 B로 바꾸는데 필요한 연산의 최솟값을 구해보자.</p >
27+
28+ ### 입력
29+
30+ <p >첫째 줄에 A, B (1 ≤ A < B ≤ 10<sup >9</sup >)가 주어진다.</p >
31+
32+ ### 출력
33+
34+ <p >A를 B로 바꾸는데 필요한 연산의 최솟값에 1을 더한 값을 출력한다. 만들 수 없는 경우에는 -1을 출력한다.</p >
35+
You can’t perform that action at this time.
0 commit comments