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:dfs 纯是自己做的,一次ac了,太爽了!!In Reply To:Re:dfs 纯是自己做的,一次ac了,太爽了!! Posted by:15038029147 at 2010-04-18 22:40:53 #include<iostream> #include<cstring> #define N 101 char map[N][N]; int n,m,sum; void dfs(int i,int j) { if(map[i][j]!='@'||i<0||j<0||i>=m||j>=n) return; else { map[i][j]='.';//已访问,覆盖 dfs(i-1,j-1);//朝其余的8个方向搜索 dfs(i-1,j); dfs(i-1,j+1); dfs(i,j-1); dfs(i,j+1); dfs(i+1,j-1); dfs(i+1,j); dfs(i+1,j+1); } } int main() { //freopen("in.txt","r",stdin); int i,j; while(scanf("%d%d",&m,&n)!=EOF) { if(m==0) break; sum=0; for(i=0;i<m;i++) scanf("%s",map[i]); for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(map[i][j]=='@') { dfs(i,j); sum++; } } } 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