-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16953.cpp
More file actions
50 lines (42 loc) · 902 Bytes
/
Copy path16953.cpp
File metadata and controls
50 lines (42 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
struct Point{
long long int num;
long long int cnt;
};
Point p;
int main() {
queue <Point> q;
long long a,b,x,cnt;
scanf("%lld %lld", &a, &b);
p.num = a;
p.cnt = 1;
q.push(p);
int result=-1;
while(!q.empty()){
x = q.front().num;
cnt = q.front().cnt;
q.pop();
if(x==b){
result = cnt;
break;
}
long long int n1 = x*2;
long long int n2 = x*10+1;
if(n1 <= b){
p.num = n1;
p.cnt = cnt+1;
q.push(p);
}
if(n2 <= b){
p.num = n2;
p.cnt = cnt+1;
q.push(p);
}
}
printf("%d", result);
return 0;
}