//p1331
#include<bits/stdc++.h>
using namespace std;
int r,c; //行与列
char maps[1010][1010]; //存放字符
int ans; //计数
void dfs(int x,int y) //深搜此坐标下的八个方位
{
maps[x][y] = '.'; //为避免后续重复,赋值为海域
for(int i=-1;i<=1;i++)
for(int j=-1;j<=1;j++)//循环八个方位
{
int dx=x+i;
int dy=y+j;
if(dx>=0 && dx<r && dy>=0 && dy<c && maps[dx][dy]=='#')//判断每个方位下是否还能继续深搜
{
dfs(dx,dy);
}
}
}
int main()
{
cin>>r>>c;
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
{
cin>>maps[i][j];
}
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)//遍历每个点
{
if(maps[i][j]=='#')//如果是船则深搜
{
dfs(i,j);//如果深搜结束则船附近所有相连接的#已替换
ans++;
}
}
if(ans==0)
cout<<"Bad placement.";
else
printf("There are %d ships.",ans);
return 0;
}
谢谢