题目链接:
#include#include #include using namespace std;#define MAXN 200000int key[MAXN];///走到key[i]的步数bool vis[MAXN];///是否走过int bfs(int first,int last){ int v; queue q; ///初始化没有走过 memset(vis,false,sizeof(vis)); q.push(first); key[first]=0; vis[first]=true; while(!q.empty()) { v=q.front(); q.pop(); if(v==last) return key[v]; ///向左走 if((v-1)>=0&&(v-1) =0&&(v+1) =0&&(v*2)