You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.0 KiB

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 10, M = 12;
int a[M][M];
#define x first
#define y second
typedef pair<int, int> PII;
int dx[] = {-1, 0, 1, 0}; //上右下左
int dy[] = {0, 1, 0, -1}; //上右下左
void bfs() {
queue<PII> q;
q.push({0, 0});
while (q.size()) {
auto t = q.front();
q.pop();
int tx = t.x, ty = t.y;
for (int i = 0; i < 4; i++) {
int x = tx + dx[i], y = ty + dy[i];
if (x < 0 || x == M || y < 0 || y == M) continue;
if (a[x][y] == 0) {
a[x][y] = -1;
q.push({x, y});
}
}
}
}
int main() {
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
cin >> a[i][j];
}
}
bfs();
int cnt = 0;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (a[i][j] == 0) cnt++;
}
}
printf("%d", cnt);
return 0;
}