社区讨论

90分,#2WA了

P2615[NOIP 2015 提高组] 神奇的幻方参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@lzeybyoo
此快照首次捕获于
2024/08/04 10:36
2 年前
此快照最后确认于
2024/08/04 11:43
2 年前
查看原帖
求帮助。
CPP
#include<bits/stdc++.h>
using namespace std;
int a[39][39];
int main(){
    int n;
    cin >> n;
    int x = n / 2, y = 0, p = 1, t = n * n;
    a[x][y] = p;
    while(p <= t){
        x++; y--;
        if(x == n && y < 0){
            x--; y += 2;
        }
        else if(x == n) x = 0;
        else if(y < 0) y = n - 1;
        else if(a[x][y]){
            x--; y += 2;
        }
        a[x][y] = ++p;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cout << a[j][i] << ' ';
        }
        cout << endl;
    }
    return 0;
}

回复

1 条回复,欢迎继续交流。

正在加载回复...