HDU - 6235 Permutation (2017CCPC哈尔滨 思维)

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
 
   
1 6
 

Sample Output
 
   
1 3 2 6 4 5
 


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


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



#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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





你可能感兴趣的:(————ACM相关————,——数学相关——,ACM,-,数列相关)