Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:我靠,这题阴。注意是百万以上哈,小于百万就RE

Posted by hustzhangyt at 2010-08-24 16:44:06 on Problem 3278
In 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator