#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
constexpr int N = 1e3 + 10, inf = 0x3f3f3f3f;
char a[N][N];
bool vis[N][N];
int n;
int dir[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};
bool flag;
bool in(int x, int y)
{
return x >= 1 & x <= n && y >= 1 && y <= n;
}
bool check(int x, int y)
{
int cnt = 0;
for (int i = 0; i < 4; i++)
{
int tx = x + dir[i][0];
int ty = y + dir[i][1];
if (a[tx][ty] == '#')
{
cnt++;
}
}
if (cnt == 4)
{
// cout << x << ' ' << y << endl;
return true;
}
return false;
}
void dfs(int x, int y)
{
vis[x][y] = true;
if (check(x, y) && flag == false)
{
flag = true;
}
for (int i = 0; i < 4; i++)
{
int tx = x + dir[i][0];
int ty = y + dir[i][1];
if (in(tx, ty) && a[tx][ty] == '#' && !vis[tx][ty])
{
dfs(tx, ty);
}
}
}
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cin >> a[i][j];
}
}
int cnt = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
flag = false;
if (!vis[i][j] && a[i][j] == '#')
{
dfs(i, j);
if (flag == false)
{
cnt++;
}
}
}
}
// for (int i = 1; i <= n; i++)
// {
// for (int j = 1; j <= n; j++)
// {
// if (vis[i][j])
// {
// cout << '*';
// }
// else
// {
// cout << '.';
// }
// }
// cout << endl;
// }
cout << cnt << endl;
}
signed main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
while (T--)
{
solve();
}
return 0;
}
06-03
762

03-01
157
