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> #include <stdlib.h> #include <string.h> #define N 21 int h,w,count=1,x0,y0; char a[N][N]; const int d[4][2]={(-1,0),(1,0),(0,-1),(0,1)}; int check(int x,int y) { int j; if(x<0||x>=h||y<0||y>=w||'#'==a[x][y]||a[x][y]=='0'||a[x][y]=='@') j=-1; else j=1; return j; } void dfs(int x,int y) { int i,j,x1,y1; for(i=0;i<4;i++) { x1=x+d[i][0]; y1=y+d[i][1]; j=check(x1,y1); if(j==1) { count++; a[x1][y1]='0'; dfs(x1,y1); } } return ; } int main() { int i,j; count=1; memset(a,0,sizeof(a)); while(scanf("%d%d",&w,&h)&&h!=0&&w!=0) { for(i=0;i<h;i++) scanf("%s",a[i]); for(i=0;i<h;i++) { for(j=0;j<w;j++) { if(a[i][j]=='@') { x0=i; y0=j; } } } dfs(x0,y0); 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