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.
45 lines
1.1 KiB
45 lines
1.1 KiB
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 10, M = 12;
|
|
int a[M][M]; //上下左右都是0,相当于在外围加了一圈0
|
|
#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];
|
|
|
|
//从左上角开始Flood Fill
|
|
bfs();
|
|
|
|
//枚举一下计算数值0的个数
|
|
int cnt = 0;
|
|
for (int i = 1; i <= N; i++)
|
|
for (int j = 1; j <= N; j++)
|
|
if (!a[i][j]) cnt++;
|
|
cout << cnt << endl;
|
|
return 0;
|
|
}
|