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 |
小水 贴码留念~~~~#include<stdio.h> int n,m; char s[21][21]; int visit[21][21]; int count; void dfs(int x,int y) { visit[x][y]=1; if(x-1>0&&!visit[x-1][y]&&s[x-1][y]=='.') { count++; dfs(x-1,y); } if(y-1>0&&!visit[x][y-1]&&s[x][y-1]=='.') { count++; dfs(x,y-1); } if(x+1<=n&&!visit[x+1][y]&&s[x+1][y]=='.') { count++; dfs(x+1,y); } if(y+1<=m&&!visit[x][y+1]&&s[x][y+1]=='.') { count++; dfs(x,y+1); } } int main (void) { int i,j; int x,y; while(scanf("%d %d",&m,&n),n!=0||m!=0) { count=1; for(i=1;i<21;i++) for(j=1;j<21;j++) visit[i][j]=0; for(i=1;i<=n;i++) { getchar(); for(j=1;j<=m;j++) { scanf("%c",&s[i][j]); if(s[i][j]=='@') { x=i; y=j; } } } dfs(x,y); printf("%d\n",count); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator