题面传送门
直接 b f s bfs bfs即可。
代码实现:
#include
#include
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
int a[1539][1539],x,y,n,m,k,ans,tot,pus,f[1539][1539],nowx,nowy,d[1539*1539];
int xp[9]={0,1,0,-1,0,1,1,-1,-1};
int yp[9]={0,0,1,0,-1,1,-1,1,-1};
struct yyy{int x,y;}tmp;
queue<yyy> q;
char s;
int main(){
// freopen("star.in","r",stdin);
// freopen("star.out","w",stdout);
register int i,j,h;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
s=getchar();
while(s!='*'&&s!='.') s=getchar();
if(s=='*') a[i][j]=1;
}
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(!f[i][j]&&a[i][j]){
ans=1;
q.push((yyy){i,j});
f[i][j]=1;
while(!q.empty()){
tmp=q.front();
q.pop();
for(h=1;h<=8;h++){
nowx=tmp.x+xp[h];nowy=tmp.y+yp[h];
if(a[nowx][nowy]&&!f[nowx][nowy]) q.push((yyy){nowx,nowy}),ans++,f[nowx][nowy]=1;
}
}
d[ans]+=ans;
if(d[ans]==ans)tot++;
pus=max(pus,d[ans]);
}
}
}
printf("%d %d\n",tot,pus);
}