hdu1998 bjfu1272奇数阶幻方构造

时间:2022-09-07 22:43:09

这题就是一个sb题,本来很水,硬是说得很含混。奇数阶幻方构造其实有好多方法,这题既不special judge,也不说清楚,以为这样能把水题变成难题似的,简直想骂出题人。

/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
const int MAXN = ;
int data[MAXN][MAXN]; int main() {
int T, n;
scanf("%d", &T);
for (int t = ; t <= T; t++) {
scanf("%d", &n);
memset(data, , sizeof(data));
int i = , j = n / ;
data[i][j] = ;
for (int k = ; k <= n * n; k++) {
int x = (i - + n) % n;
int y = (j + ) % n;
if (data[x][y] > ) {
y = j;
x = (i + ) % n;
}
data[x][y] = k;
i = x;
j = y;
}
for (i = ; i < n; i++) {
for (j = ; j < n; j++) {
printf("%4d", data[i][j]);
}
putchar('\n');
}
}
return ;
}