HDU

来源:互联网 发布:陕西广电网络换门庭 编辑:程序博客网 时间:2024/04/30 12:46

Permutation


Problem Description
A permutation p1,p2,...,pn of 1,2,...,n is called a lucky permutation if and only if pi0(mod|pipi2|) for i=3...n.

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

Input
The first line is the number of test cases.

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

Output
For each test case, output a single line with n numbers p1,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
16
 

Sample Output
1 3 2 6 4 5
 


题意:很简单。要注意是排列,就所有数字只能用一次。


解题思路:任何数模1,都为0.所以……看代码……



#include<iostream>#include<deque>#include<memory.h>#include<stdio.h>#include<map>#include<string.h>#include<algorithm>#include<vector>#include<math.h>#include<stack>#include<queue>#include<set>using namespace std;typedef long long int ll;int a[100005];int main(){    int t;    scanf("%d",&t);    while(t--){        int n;        scanf("%d",&n);        a[1]=1;        if(n%2)            a[2]=n/2+2;        else            a[2]=n/2+1;        for(int i=3;i<=n;i++)            a[i]=a[i-2]+1;        for(int i=1;i<n;i++)            cout<<a[i]<<" ";        cout<<a[n]<<endl;    }    return 0;}