hdu1998 bjfu1272奇数阶幻方构造

这题就是一个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 = 33;
int data[MAXN][MAXN];

int main() {
    int T, n;
    scanf("%d", &T);
    for (int t = 1; t <= T; t++) {
        scanf("%d", &n);
        memset(data, 0, sizeof(data));
        int i = 0, j = n / 2;
        data[i][j] = 1;
        for (int k = 2; k <= n * n; k++) {
            int x = (i - 1 + n) % n;
            int y = (j + 1) % n;
            if (data[x][y] > 0) {
                y = j;
                x = (i + 1) % n;
            }
            data[x][y] = k;
            i = x;
            j = y;
        }
        for (i = 0; i < n; i++) {
            for (j = 0; j < n; j++) {
                printf("%4d", data[i][j]);
            }
            putchar('\n');
        }
    }
    return 0;
}

 

posted @ 2015-01-29 21:09  moonbay  阅读(144)  评论(0编辑  收藏  举报