RT
写了一个最后一个样例都过不去的程序,AC了???
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node{
int x,t;
};
queue<node>q;
int n,ans,vis[3000001];
void bfs(){
q.push((node){1,0});
while(!q.empty()){
node a=q.front();
q.pop();
if(a.x<1 || a.x>2*n || vis[a.x]) continue;
if(a.x==n){
cout<<a.t;
exit(0);
}
vis[a.x]=1;
a.t++;
q.push((node){a.x-1,a.t});
q.push((node){a.x+1,a.t});
q.push((node){a.x*2,a.t});
}
}
signed main(){
cin>>n;
bfs();
return 0;
}