题目大意:题目链接
就是给你N,K,每次有三种惭怍+1,-1,*2,,问多少次操作能到K
解题思路,搜索直接算,。,,,哎,啥时候这种垃圾搜索我能直接A 啊,太菜了
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn = 1000000+10;int vis[maxn]={0};int main()
{int n,k;while(~scanf("%d%d",&n,&k)){memset(vis,0,sizeof(vis));int t;queue<int> q;q.push(n);while(!q.empty()){t = q.front();q.pop();if(t==k) break;if(t > 0 && !vis[t-1]){int z;z=t-1;vis[z]=vis[t]+1;q.push(z);}if(t<k && !vis[t+1]){int z=t+1;vis[z]=vis[t]+1;q.push(z);}if(t*2< maxn && !vis[t*2]){int z=t*2;vis[z]=vis[t]+1;q.push(z);}}printf("%d\n",vis[k]);}return 0;
}