想请教一下这里的编译出错是为什么?
查看原帖
想请教一下这里的编译出错是为什么?
813166
LXiao1221楼主2022/11/25 14:26
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;

const int N = 40;
int g[N][N];
PII pos[N * N];

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL);

    int n;
    cin >> n;

    int cnt = n / 2 + 1;

    g[0][cnt] = 1;
    pos[1] = {0, cnt};
    for(int k = 2;k <= n * n;k ++)
    {
        if(pos[k - 1].first == 0 && pos[k - 1].second != n - 1) pos[k] = {n - 1, pos[k - 1].second + 1}, g[pos[k].first][pos[k].second] = k;
        else if(pos[k - 1].first != 0 && pos[k - 1].second == n - 1) pos[k] = {pos[k - 1].first - 1, 0}, g[pos[k].first][pos[k].second] = k;
        else if(pos[k - 1].first == 0 && pos[k - 1].second == n - 1) pos[k] = {pos[k - 1].first - 1, pos[k - 1].second}, g[pos[k].first][pos[k].second] = k;
        else if(pos[k - 1].first != 0 && pos[k - 1].second != n - 1) 
        {
            if(g[pos[k - 1].first - 1][pos[k].second + 1] == 0) pos[k] = {pos[k - 1].first - 1, pos[k].second + 1}, g[pos[k].first][pos[k].second] = k;
            else pos[k] = {pos[k].first - 1, pos[k].second}, g[pos[k].first][pos[k].second] = k;
        }
    }

    for(int i = 0;i < n;i ++)
    {   
        for(int j = 0;j < n;j ++) 
            cout << g[i][j] << ' ';
        cout << endl;
    }

    return 0;
}

2022/11/25 14:26
加载中...