每个节点处有三种走法:+1, -1和*2;
#include<iostream>
#include<queue>
using namespace std;
const int MAXN = 100001;
bool visit[MAXN];
int step[MAXN];
queue<int> que;
int bfs(int n, int k)
{
int head, next;
que.push(n);
visit[n] = true;
step[n] == 0;
while(!que.empty())
{
head = que.front();
que.pop();
for(int i = 0; i < 3; i++)
{
if(i == 0) {next = head + 1;}
else if(i == 1){next = head - 1;}
else next = head * 2;
if (next > MAXN || next < 0) continue;
if(!visit[next])
{
que.push(next);
step[next] = step[head] + 1;
visit[next] = true;
}
if(next == k) {return step[next]; }
}
}
}
int main()
{
int n, k;
cin >> n >> k;
cout << bfs(n, k) << endl;
return 0;
}