显示代码纯文本
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<deque>
#include<queue>
#include<stack>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<functional>
using namespace std;
ifstream fin("lakecounting.in");
ofstream fout("lakecounting.out");
int map[110][110],dfs[110][110],m,n;//地图,标记,长,宽
void Research(int i,int j)
{
if(map[i][j]==0||dfs[i][j]==1)return;
dfs[i][j]=1;
Research(i-1,j-1);Research(i-1,j);Research(i-1,j+1);
Research(i,j-1); Research(i,j+1);
Research(i+1,j-1);Research(i+1,j);Research(i+1,j+1);
}
int main()
{
fin>>n>>m;char k;int ans=0;//计数器
memset(map,0,sizeof(map));memset(dfs,0,sizeof(dfs));//清零
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
fin>>k;
if(k=='W')map[i][j]=1;
else map[i][j]=0;
//干的地记为0;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(map[i][j]==1&&dfs[i][j]==0)
{ans++;Research(i,j);}
}
}
fout<<ans<<endl;
return 0;
}