pi≡0(mod|pi−pi−2|) (思维题)

Problem

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|)的数字序列。

分析:当一个数字序列的奇数位置与偶数位置上,任意两个相邻的数的差等于1时,恰好满足题目要求。

#include 
using namespace std;
const int MAXN = 1e5+10;
int a[MAXN];
int main() {
	int t, n;
	cin>>t;
	while(t--) {
		cin>>n;
		int cnt = 1;
		for(int i = 1; i <= n; i += 2) {//奇数位置,从1开始,随着位置向右递增,cnt++;
			a[i] = cnt++;
		}
		for(int i = 2; i <= n; i += 2) {//偶数位置
			a[i] = cnt++;
		}
		for(int i = 1; i <= n; i++) {
			if(i == n) {
				cout<

 

你可能感兴趣的:(pi≡0(mod|pi−pi−2|) (思维题))