您的位置:首页 > 其它

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

2017-11-12 19:51 405 查看


Permutation

Problem Description

A permutation p1,p2,...,pn of 1,2,...,n is
called a lucky permutation if and only if pi≡0(mod|pi−pi−2|) 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(3≤n≤105).

 

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<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
<<endl;

}

return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: