标签:... field std pool ike algo pre for john
Input
Output
Sample Input
10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.....W. .W.W......W. ..W.......W.
Sample Output
3
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 const int maxn = 1e2+10; 7 char a[maxn][maxn]; 8 int cnt=0; 9 int n,m; 10 11 void DFS(int i,int j){ 12 for( int p=-1; p<=1; p++ ){ 13 for( int q=-1; q<=1; q++ ){ 14 int x=i+p; 15 int y=j+q; 16 if(x>=0&&x<=n-1&&y>=0&&y<=m-1&&a[x][y]==‘W‘){ 17 a[x][y]=‘.‘; 18 DFS(x,y); 19 } 20 } 21 } 22 } 23 24 int main(){ 25 while(~scanf("%d%d",&n,&m)&&n&&m){ 26 memset(a,‘0‘,sizeof(a)); 27 cnt=0; 28 for( int i=0; i<n; i++ ){ 29 scanf("%s",a[i]); 30 } 31 for( int i=0; i<n; i++){ 32 for( int j=0; j<m; j++ ){ 33 if(a[i][j]==‘W‘){ 34 cnt++; 35 DFS(i,j); 36 } 37 } 38 } 39 printf("%d\n",cnt); 40 } 41 return 0; 42 }
标签:... field std pool ike algo pre for john
原文地址:https://www.cnblogs.com/Bravewtz/p/10604735.html