标签:spec clu space har memset classname source keyword ret
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define p 100010
using namespace std;
int visit[p];
int n,k;
struct Catch{
int step;
int x;
Catch(int xx,int s):x(xx),step(s){}
};
queue<Catch> q;
int main(){
scanf("%d %d",&n,&k);
memset(visit,0,sizeof(visit));
q.push(Catch(n,0));
visit[n]=1;
while(!q.empty()){
Catch c=q.front();
q.pop();
if(c.x==k)
{
printf("%d\n",c.step);
return 0;
}
else
{
if(c.x-1>=0&&!visit[c.x-1])
{
q.push(Catch(c.x-1,c.step+1));
visit[c.x-1]=1;
}
if(c.x+1<p&&!visit[c.x+1])
{
q.push(Catch(c.x+1,c.step+1));
visit[c.x+1]=1;
}
if(c.x*2<p&&!visit[c.x*2])
{
q.push(Catch(c.x*2,c.step+1));
visit[c.x*2]=1;
}
}
}
}
标签:spec clu space har memset classname source keyword ret
原文地址:https://www.cnblogs.com/zssd/p/10261284.html