标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16542 Accepted Submission(s):
9500
#include<stdio.h> #include<string.h> #define MAX 110 char s[MAX][MAX]; int n,m; void dfs(int x,int y) { if(0<=x&&x<n&&0<=y&&y<m&&s[x][y]==‘@‘) { s[x][y]=‘*‘;//将判断过的位置标记 dfs(x-1,y);//搜索上边 dfs(x+1,y);//搜索下边 dfs(x,y-1);//搜索左边 dfs(x,y+1);//搜索右边 dfs(x-1,y-1);//搜索左上 dfs(x-1,y+1);//搜索右上 dfs(x+1,y-1);//搜索左下 dfs(x+1,y+1);//搜索右下 } } int main() { int j,i,sum,t,k; while(scanf("%d%d",&n,&m)&&n!=0&&m!=0) { for(i=0;i<n;i++) { scanf("%s",s[i]); } sum=0; for(i=0;i<=n;i++) { for(j=0;j<m;j++) { if(s[i][j]==‘@‘) { dfs(i,j); sum++; } } } printf("%d\n",sum);//搜索次数就为油田数目 } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4575869.html