社区讨论
0pts求调
P1162填涂颜色参与者 5已保存回复 10
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 10 条
- 当前快照
- 1 份
- 快照标识符
- @mllkdno1
- 此快照首次捕获于
- 2026/02/14 08:14 5 天前
- 此快照最后确认于
- 2026/02/17 11:05 前天
CPP
#include <iostream>
#include <algorithm>
#define Please return
#define AC 0
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
using namespace std;
const int MAXN = 30 + 5;
int n, g[MAXN][MAXN];
bool vis[MAXN][MAXN];
int dx[] = {0, +1, 0, -1, 0, 0};
int dy[] = {0, 0, -1, 0, +1, 0};
void dfs(int x, int y) {
vis[x][y] = true;
for (int i = 1; i <= 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 1 || nx > n || ny < 1 || ny > n) {
continue;
}
if (g[nx][ny] == '0') {
continue;
}
if (vis[nx][ny]) {
continue;
}
g[nx][ny] = 3;
dfs(nx, ny);
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> g[i][j];
}
}
dfs(1, 1);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (g[i][j] == 3) {
cout << 1 << " ";
} else if (g[i][j] == 1) {
cout << 2 << " ";
} else {
cout << 0 << " ";
}
}
cout << endl;
}
Please AC;
}
回复
共 10 条回复,欢迎继续交流。
正在加载回复...