这个 代码混乱。。好歹过了
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
struct node
{
int cnt;
int mm;
}tmp;
queue<node> q;
int n,vis[100010];
int bfs(int m)
{
int pp;
vis[m]=1;
tmp.mm=m;
tmp.cnt=1;
q.push(tmp);
while(!q.empty())
{
tmp=q.front();
q.pop();
m=tmp.mm;
pp=tmp.cnt;
if(m-1==n) return pp;
else if(m>=1&&!vis[m-1]){
tmp.mm=m-1;
tmp.cnt=pp+1;
q.push(tmp);
vis[m-1]=1;
}
if(m+1==n) return pp;
else if(m<100000&&!vis[m+1]) {
tmp.mm=m+1;
tmp.cnt=pp+1;
q.push(tmp);
vis[m+1]=1;
}
if(m+m==n) return pp;
else if(m+m<100000&&!vis[m+m]){
tmp.mm=m+m;
tmp.cnt=pp+1;
q.push(tmp);
vis[m+m]=1;
}
}
}
int main()
{
int m,i,s,tmp,ans;
while(~scanf("%d%d",&m,&n))
{
if(m==n)
{
printf("0\n");
continue;
}
memset(vis,0,sizeof vis);
ans=bfs(m);
printf("%d\n",ans);
}
return 0;
}