Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <queue>
- using namespace std;
- queue <pair<int,int> > q;
- int main(){
- int n,m;
- cin >> n >> m;
- if (n==m){
- cout << 0 ;
- return 0;
- }
- pair <int,int> k ;
- k.first = n;
- k.second = 0;
- q.push(k);
- while(true){
- pair <int, int> k = q.front();
- pair <int,int> p;
- if (k.first*2<=10000){
- p.first = k.first*2;
- p.second = k.second+1;
- q.push(p);
- if (p.first == m){
- cout << p.second;
- return 0;
- }
- }
- if( k.first-1>=0){
- p.first = k.first-1;
- p.second = k.second+1;
- q.push(p);
- if (p.first==m){
- cout << p.second;
- return 0;
- }
- }
- q.pop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement