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:这题bfs怎么会错?大牛们帮看看啊。谢了先!

Posted by tzj115 at 2007-08-21 13:07:11 on Problem 1979
In Reply To:这题bfs怎么会错?大牛们帮看看啊。谢了先! Posted by:shenfangyi at 2006-07-26 02:20:40
> #include<stdio.h>
> #include<iostream.h>
> char a[20][21];
> int b[400][2],c[20][20];
> main()
> {
>     int w,h;
>     cin>>w>>h;
>     while(w||h)
>     {
>         getchar();
>         int i=-1;
>         for(int x=0;x<h;x++)
>         {
>             gets(a[x]);
>             for(int j=0;j<w;j++)c[x][j]=0;
>             if(i)
>             {
>                 for(int j=0;j<w;j++)if(a[x][j]=='@')
>                 {
>                     i++,b[0][0]=x,b[0][1]=j;
>                 }
>             }
>         }
>         int j=1;
>         while(i<j)
>         {
>             if((b[i][0]>0)&&(a[b[i][0]-1][b[i][1]]=='.')&&(!c[b[i][0]-1][b[i][1]]))b[j][0]=b[i][0]-1,b[j][1]=b[i][1],c[b[j][0]][b[j][1]]=1,j++;
>             if((b[i][1]>0)&&(a[b[i][0]][b[i][1]-1]=='.')&&(!c[b[i][0]][b[i][1]-1]))b[j][0]=b[i][0],b[j][1]=b[i][1]-1,c[b[j][0]][b[j][1]]=1,j++;
>             if((b[i][0]<h-1)&&(a[b[i][0]+1][b[i][1]]=='.')&&(!c[b[i][0]+1][b[i][1]]))b[j][0]=b[i][0]+1,b[j][1]=b[i][1],c[b[j][0]][b[j][1]]=1,j++;
>             if((b[i][0]<w-1)&&(a[b[i][0]][b[i][1]+1]=='.')&&(!c[b[i][0]][b[i][1]+1]))b[j][0]=b[i][0],b[j][1]=b[i][1]+1,c[b[j][0]][b[j][1]]=1,j++;
>             i++;
>         }
>         cout<<j<<endl;
>         cin>>w>>h;
>     }
> }
//确实 代码太难看了 !!!注意可读性!!!

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