#include using namespace std; const int N = 10, M = 12; int a[M][M]; //上下左右都是0,相当于在外围加了一圈0 #define x first #define y second typedef pair PII; int dx[] = {-1, 0, 1, 0}; //上右下左 int dy[] = {0, 1, 0, -1}; //上右下左 void bfs() { queue 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 = 0; i < M; i++) for (int j = 0; j < M; j++) if (a[i][j] == 0) cnt++; cout << cnt << endl; return 0; }