HDU - 6235 Permutation

A permutation p1,p2,...,pnp1,p2,...,pn of 1,2,...,n1,2,...,n is called a lucky permutation if and only if pi≡0(mod|pi−pi−2|)pi≡0(mod|pi−pi−2|) for i=3...ni=3...n. 

Now you need to construct a lucky permutation with a given nn. 

Input

The first line is the number of test cases. 

For each test case, one single line contains a positive integer n(3≤n≤105)n(3≤n≤105). 

Output

For each test case, output a single line with nn numbers p1,p2,...,pnp1,p2,...,pn. 

It is guaranteed that there exists at least one solution. And if there are different solutions, print any one of them. 

Sample Input

1
6

Sample Output

1 3 2 6 4 5

给你序列长度 要求输出一个数列 满足pi≡0(mod|pi−pi−2|)。

0(mod x)的意思是 这个数除以x的余数为0 就是x的倍数。也就是pi是|pi−pi−2|的倍数。保证|pi−pi−2|为1就行。

思维不难 但是公式的意思看了我好久……

ac代码:

#include 
#include 
#include 
using namespace std;
int a[100010];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int cnt=1;
        for(int i=1;i<=n;i+=2)
            a[i]=cnt++;
        for(int i=2;i<=n;i+=2)
            a[i]=cnt++;
        for(int i=1;i

 

你可能感兴趣的:(训练)