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 |
Re:我靠,这题阴。注意是百万以上哈,小于百万就REIn Reply To:我靠,这题阴。注意是百万以上哈,小于百万就RE Posted by:dynamic_study at 2009-08-09 09:51:57 不是这样的! 我AC了,可是还是搞不懂加注释的地方。 #define N 100005 void bfs(int x,int k){ memset(steps,0,sizeof steps); memset(flag,false,sizeof flag); int head=0,tail=1; Queue[0]=x; flag[x]=true; while(head<tail){ //之前这里是while(1){} RE了好几次!!! int tmp=Queue[head++]; if(tmp-1>=0&&!flag[tmp-1]){ Queue[tail++]=tmp-1; steps[tmp-1]=steps[tmp]+1; flag[tmp-1]=true; if(tmp-1==k) return; } if(tmp+1<=N&&!flag[tmp+1]){ Queue[tail++]=tmp+1; steps[tmp+1]=steps[tmp]+1; flag[tmp+1]=true; if(tmp+1==k) return; } if(tmp*2<=N&&!flag[tmp*2]){ Queue[tail++]=tmp*2; steps[tmp*2]=steps[tmp]+1; flag[tmp*2]=true; if(tmp*2==k) return; } } return ; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator