0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 18:52:02 +00:00

P1162 填涂颜色

R40559078
This commit is contained in:
Baoshuo Ren 2020-10-26 17:24:18 +08:00 committed by Baoshuo Ren
parent f1193a1568
commit 2933e72b04
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

48
problem/P1162/P1162.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <bits/stdc++.h>
using namespace std;
int n, a[32][32], b[32][32];
int dx[] = {0, -1, 1, 0, 0};
int dy[] = {0, 0, 0, -1, 1};
void dfs(int x, int y) {
if (x < 0 || x > n + 1 || y < 0 || y > n + 1 || b[x][y] != 0) {
return;
}
b[x][y] = 2;
for (int i = 1; i <= 4; i++) {
dfs(x + dx[i], y + dy[i]);
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
if (a[i][j] == 0) {
b[i][j] = 0;
}
else {
b[i][j] = 1;
}
}
}
dfs(0, 0);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (b[i][j] == 2) {
cout << "0 ";
}
else if (b[i][j] == 0) {
cout << "2 ";
}
else {
cout << "1 ";
}
}
cout << endl;
}
return 0;
}