简单易懂超暴力
第九届蓝桥杯第九题
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
char mp[maxn][maxn];
int vis[maxn][maxn];
int ans[100005];
int n;
void dfs(int x, int y, int cnt) {
if (x < 0 || y < 0 || x >= n|| y >= n)
return;
if (vis[x][y])
return;
if (mp[x][y] == '.')
return;
vis[x][y] = 1;
if (mp[x-1][y] == '#' && mp[x+1][y] == '#' && mp[x][y-1] == '#' && mp[x][y+1] == '#')
ans[cnt]++;
dfs(x-1,y,cnt);
dfs(x+1,y,cnt);
dfs(x,y-1,cnt);
dfs(x,y+1,cnt);
}
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin>>mp[i][j];
int len = 0;
for (int i = 0; i < n; i++) {
for (int j=0; j<n; j++) {
if(mp[i][j] == '#' && !vis[i][j]) {
dfs(i, j, len);
len ++;
}
}
}
int sum = 0;
for (int i = 0; i < len; i++)
if (ans[i] == 0) sum++;
cout << sum << endl;
}