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 <cstdio>
#include <cstring>
#include <iostream>
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<n;i++)
        cout<<a[i]<<' ';
        cout<<a[n]<<endl;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_41333002/article/details/82824375
今日推荐