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 |
通俗易懂 GCC 0s#include<stdio.h> #include<stdlib.h> char room[20][20]; int dfs(char room[][20],int h,int w,int i,int j){ if(i<0||i>=h||j<0||j>=w||room[i][j]=='#') return 0; int n=1; room[i][j]='#'; n+=(dfs(room,h,w,i+1,j)+dfs(room,h,w,i-1,j)+dfs(room,h,w,i,j+1) +dfs(room,h,w,i,j-1)); return n; } int main(){ int w,h; while(scanf("%d%d",&w,&h)!=EOF){ if(w==0||h==0) break; int sum,i,j,t1,t2; for(i=0;i<h;i++){ scanf("%s",&room[i]); } for(i=0;i<h;i++){ for(j=0;j<w;j++){ if(room[i][j]=='@'){ t1=i;t2=j; } } } sum=dfs(room,h,w,t1,t2); printf("%d\n",sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator