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 |
Re:那位帮忙看一下,不知哪错了,谢谢!In Reply To:那位帮忙看一下,不知哪错了,谢谢! Posted by:chenyy at 2007-08-30 16:34:12 #include <stdio.h> char map[100][100]; int num; int dir[4][2] = {{0,-1},{0,1},{1,0},{-1,0}}; int n,m; void dfs(int si,int sj) { int x,y,i; if (si>m||sj>n||si<=0||sj<=0) { return; } if (map[si][sj]=='.') { num++; map[si][sj]='#'; for(i=0;i<4;i++) { x=si+dir[i][0], y=sj+dir[i][1]; if(map[x][y]=='.') { dfs(x,y); } } } } int main() { int i,j,si,sj; while(scanf("%d%d",&n,&m)!=EOF&&!(n==0&&m==0)) { getchar();num=0; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { scanf("%c", &map[i][j]); if(map[i][j]=='@') { si=i;sj=j; } } getchar(); } map[si][sj]='.'; dfs(si,sj); printf("%d\n",num); } return 0; } ================================================================= 看下我AC的 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator