满脑子dp简直魔性
模拟题意bfs转移即可#include#include #include using namespace std;const int N=200005;int s,t,d[N];bool v[N];queue q;inline void wk(int x,int y){ d[y]=d[x]+1; if(!v[y]) { v[y]=1; q.push(y); }}int main(){ scanf("%d%d",&s,&t); for(int i=0;i<=200000;i++) d[i]=1e9; v[s]=1,d[s]=0,q.push(s); while(!q.empty()) { int u=q.front(); q.pop(); v[u]=0; if(u*2<=200000&&d[u*2]>d[u]+1) wk(u,u*2); if(u+1<=200000&&d[u+1]>d[u]+1) wk(u,u+1); if(u-1>=0&&d[u-1]>d[u]+1) wk(u,u-1); } printf("%d\n",d[t]); return 0;}