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 |
这题bfs怎么会错?大牛们帮看看啊。谢了先!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator