g++ wa了,c++ ac了,渣渣不懂,这道题。。。
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <stdlib.h>
using namespace std;
bool mapp[100005];
int walk[100005];
int f,l;
int bfs()
{
memset(mapp,0,sizeof(mapp));
queue<int>q;
q.push(f);
mapp[f]=1;
walk[f]=0;
while(!q.empty())
{
int tmp=q.front();
q.pop();
for(int i=0;i<3;i++)
{
int next;
if(i==0)next=tmp-1;
else if(i==1)next=tmp+1;
else next=tmp*2;
if(next<0||next>100000||mapp[next])continue;
if(!mapp[next])
{
q.push(next);
mapp[next]=1;
walk[next]=walk[tmp]+1;
}
if(next==l)return walk[next];
}
}
}
int main()
{
cin>>f>>l;
if(f>=l)cout<<f-l<<endl;
else cout<<bfs()<<endl;
return 0;
}