全RE
查看原帖
全RE
1035847
Tomatos03楼主2024/2/27 21:54
#include <bits/stdc++.h>
//----mxcro----------------
#define MAXN int(40)
#define BASE 121
#define endl '\n'
#define rep(i, starts, ends) for(int i = starts; i <= ends; ++i)
//----namespace------------
using namespace std;
//----struct---------------
struct node{ int x, y;};
//----constxnt-------------
const double eps = 1e-4;
//----verious-------------
int n, a[MAXN][MAXN] = {0};
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool vis[MAXN][MAXN] = {0};
//----mathod-----------

void dfs(int x, int y) {
    if (x < 0 || x > n + 1|| y < 0 || y > n + 1) return;
    a[x][y] = 3;
    rep(i, 0, 3) {
        int new_x = x + dx[i], new_y = y + dy[i];
        if (vis[new_x][new_y]) continue;
        vis[new_x][new_y] = true;
        dfs(new_x, new_y);
    }
}

void solve() {
    cin >> n;
    rep(i, 1, n) {
        rep(j, 1, n) {
            cin >> a[i][j];
            vis[i][j] = a[i][j];
            if (a[i][j] == 0) a[i][j] = 2;
        }
    }
    vis[0][0] = true;
    dfs(0, 0);
    rep(i, 1, n) {
        rep(j, 1, n) {
            if (a[i][j] == 3) cout << 0 << " ";
            else cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*
    int t;
    cin >> t;
    while(t-- > 0) {
        solve();
    }
    */
    solve();
    return 0;
}
2024/2/27 21:54
加载中...