#include<bits/stdc++.h>
using namespace std;
struct Node{
int x;
int y;
};
queue<Node> q;
int n,m;
char a[405][405];
int c=0;
int dx[8]={1,1,1,0,0,-1,-1,-1};
int dy[8]={0,1,-1,1,-1,0,1,-1};
void bfs(int i,int j){
Node node;
node.x = i;
node.y = j;
q.push(node);
a[i][j]='.';
while(!q.empty()){
Node w = q.front();
for(int i=0;i<8;i++){
int lx = w.x + dx[i];
int ly = w.y + dy[i];
if(lx>=0 && lx<=n && ly>=0 && ly<=m && a[lx][ly]=='W'){
Node n;
n.x = lx;
n.y = ly;
q.push(n);
a[lx][ly]='.';
}
}
q.pop();
}
c++;
}
int main(){
ios::sync_with_stdio(0);
cin>>n>>m;
for(int i=0;i<n;i++){
string s;
cin>>s;
for(int j=0;j<m;j++){
a[i][j]=s[j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(a[i][j]=='.') continue;
bfs(i,j);
}
}
cout<<c;
return 0;
}
LakeCounting
最新推荐文章于 2024-07-13 19:27:27 发布