【HDU-6235】Permutation

【HDU-6235】Permutation

问题链接:https://vjudge.net/problem/HDU-6235

Solution:

Special Judge,想出来如何构造后,会感叹竟然有这么简单的题,先在奇数位置上从1开始每次递增1排过去,奇数位置排完,接着排偶数位置,这样任意相间排列的数之差都是1,显然1是任何数的因数。

#include <iostream>

using namespace std;

int main(void) {
    int t, n;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        int bound = (n + 1) / 2;
        for (int i = 1; i <= bound; i++) {
            if (i - 1) putchar(' ');
            printf("%d", i);
            putchar(' ');
            if (i + bound <= n) printf("%d", i + bound);
        }
        putchar('\n');
    }
    return 0;
}