#include<bits/stdc++.h> usingnamespace std; constint LEN = 35; int N; //四向不是八向,不然会插进圈内 int arr[LEN][LEN], vis[LEN][LEN], walk[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
//秉持正难则反的原则,直接改变圈内的不方便 //那就改变圈外,输出的时候判断一下就好 //外面应该多一圈,不然无法围绕1进行搜索 voiddfs(int x, int y) { if (x < 0 || x > N || y < 0 || y > N || arr[x][y] == -1 || arr[x][y] == 1) return; arr[x][y] = -1; for (int i = 0; i < 4; ++i) dfs(x + walk[i][0], y + walk[i][1]); }
intmain() { cin >> N; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { cin >> arr[i][j]; } } //外面多一圈 ++N; dfs(0, 0); for (int i = 1; i <= N - 1; ++i, cout << endl) { for (int j = 1; j <= N - 1; ++j) { if (arr[i][j] == -1) cout << "0 "; elseif (!arr[i][j]) cout << "2 "; else cout << "1 "; } } return0; }