Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
新菜求帮看一直错#include<stdio.h> int N,K; int vis[100001]={0}; int line[100001]={0}; int que[201001]={0}; void bfs() { int top=0,end=0; que[end++]=N; line[N]=0; while(top<end) { int nextm=que[top++];if(nextm==K)break; vis[nextm]=1; if(2*nextm<=100000&&!vis[2*nextm]&&nextm<K)\\第二种走法 { vis[2*nextm]=1; line[2*nextm]=line[nextm]+1; que[end++]=2*nextm; } if(nextm-1>=1&&!vis[nextm-1])\\第一种走法 { vis[nextm-1]=1; line[nextm-1]=line[nextm]+1; que[end++]=nextm-1; } if(nextm+1<=100000&&!vis[nextm+1]&&nextm<K)\\第一种走法 { vis[nextm+1]=1; line[nextm+1]=line[nextm]+1; que[end++]=nextm+1; } } } int main() { while(scanf("%d%d",&N,&K)!=EOF) { for(int i=0;i<100001;i++)vis[i]=0; bfs(); printf("%d\n",line[K]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator