POJ 2386 P32 挑战程序设计
#include<cstdio>
using namespace std;#define MAX_N 210
char field[MAX_N][MAX_N];
int n,m;void dfs(int x,int y){field[x][y]='.';for(int dx=-1;dx<=1;dx++){for(int dy=-1;dy<=1;dy++){int nx=x+dx,ny=y+dy;if(nx>=0&&nx<n&&ny>=0&&ny<m&&field[nx][ny]=='W') dfs(nx,ny);}}return ;
}void solve(){int res=0;for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(field[i][j]=='W'){dfs(i,j);res++;}}}printf("%d\n",res);
}int main(){scanf("%d%d",&n,&m);for(int i=0;i<n;i++){scanf("%s",field[i]);}solve();return 0;
}