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 |
啊啊啊啊,这个问题卡我两个小时,最后才发现,我写的代码有bug,最后终于解决,附上代码#include<cstdio> int dx[4]={0,0,-1,1}; int dy[4]={1,-1,0,0}; int temps,r,c; char tiles[21][21]; void dfs(int x,int y) { int nx,ny; temps++; tiles[x][y]='#'; for(int i=0;i<4;i++) { nx=x+dx[i]; ny=y+dy[i]; if(nx>=1&&nx<=r&&ny>=1&&nx<=c&&tiles[nx][ny]=='.') dfs(nx,ny); } } int main() { int x,y; while(scanf("%d%d",&c,&r)!=EOF&&r&&c) { for(int i=1;i<=r;i++) { getchar(); for(int j=1;j<=c;j++) { scanf("%c",&tiles[i][j]); if(tiles[i][j]=='@') { x=i; y=j; } } } temps=0; dfs(x,y); printf("%d\n",temps); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator