/*
第一道广搜。。。
一维广搜
算是最简单的广搜了吧
*/
#define LOCAL
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iomanip>
#include<string>
#include<algorithm>
#include<ctime>
#include<stack>
#include<queue>
#include<vector>
#define N 100000
using namespace std;
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int start,end,path[N+5];//path[]记录走过的路和走的步数
while(cin>>start>>end)
{
queue<int> q;
memset(path,-1,sizeof(path));
path[start]=0;q.push(start);
while(!q.empty())//遍历每个结点
{
start=q.front();q.pop();
if(start-1>=0&&path[start-1]==-1){q.push(start-1);path[start-1]=path[start]+1;}
if(start+1<=N&&path[start+1]==-1){q.push(start+1);path[start+1]=path[start]+1;}
if(start*2<=N&&path[start*2]==-1){q.push(start*2);path[start*2]=path[start]+1;}
}
cout<<path[end]<<endl;
}
return 0;
}
poj 3278 Catch That Cow
最新推荐文章于 2021-08-11 07:01:00 发布