#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
int n,k;
bool book[100001];
typedef struct node
{
int n;
int d;
}N;
int bfs()
{
queue<N> q;
N first;
first.n=n;
first.d=0;
q.push(first);
while(!q.empty())
{
N temp=q.front();
int a=temp.n;
int time=temp.d;
q.pop();
if(a==k)
return time;
N tep;
if(2*a<=100000&&!book[2*a])
{
tep.n=2*a;
book[2*a]=true;
tep.d=time+1;
q.push(tep);
}
if(a-1>=0&&!book[a-1])
{
book[a-1]=true;
tep.n=a-1;
tep.d=time+1;
q.push(tep);
}
if(a+1<=100000&&!book[a+1])
{tep.n=a+1;
book[a+1]=true;
tep.d=time+1;
q.push(tep);
}
}
return 0;
}
int main()
{
memset(book,false,sizeof(book));
cin>>n>>k;
cout<<bfs()<<endl;
return 0;
}
poj3278
最新推荐文章于 2020-07-18 18:44:47 发布