标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15444 Accepted Submission(s): 8863
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int dir[8][2]={1,1, 1,-1, -1,1, -1,-1, 0,1, 0,-1, 1,0, -1,0}; int n,m; char map[100][100]; void dfs(int x,int y) { int i; for(i=0;i<8;i++) { int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(map[xx][yy]==‘@‘&&xx<n&&xx>=0&&yy<m&&yy>=0) { map[xx][yy]=‘*‘; dfs(xx,yy); } } } int main() { int i,j; while(~scanf("%d%d",&n,&m)) { int cout=0; if(n==0||m==0) break; getchar(); for(i=0;i<n;i++) { scanf("%s",&map[i]); } for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(map[i][j]==‘@‘) { map[i][j]=‘*‘; dfs(i,j); cout++; } } } printf("%d\n",cout); } return 0; }
标签:
原文地址:http://www.cnblogs.com/cancangood/p/4388497.html