一直很晕,用c++16Ms过,用G++WA!!!!!!!!#include#include #define N 100000int n,k,vis[N];struct node{ int step; int num;}p[N*10];int bfs(){ memset(vis,0,sizeof(vis)); int head=0,tail=0; p[head].num=n; p[head].step=0; vis[n]=1; tail++; while(head =0&&!vis[p[head].num-1]) { p[tail].num=p[head].num-1; vis[p[head].num-1]=1; p[tail].step=p[head].step+1; tail++; } if(p[head].num*2<=N&&!vis[p[head].num*2]) { p[tail].num=p[head].num*2; vis[p[head].num*2]=1; p[tail].step=p[head].step+1; tail++; } head++; } return 0;}int main(){ while(scanf("%d%d",&n,&k)!=EOF) { int ans= bfs(); printf("%d\n",ans); }}