1. 程式人生 > >2017CCPC哈爾濱 F:Permutation(構造)

2017CCPC哈爾濱 F:Permutation(構造)

題意:

讓你構造一個1到n的全排列,滿足對於所有的i>=3,都有a[i]%|a[i]-a[i-2]|==0

思路:假設n=10

構造出的序列就是:1 6 2 7 3 8 4 9 5 10

OK

//2017CCPC哈爾濱--F
#include<stdio.h>
int a[100005];
int main(void)
{
	int T, n, i, now;
	scanf("%d", &T);
	while(T--)
	{
		scanf("%d", &n);
		now = 0;
		for(i=1;i<=n;i+=2)
			a[i] = ++now;
		for(i=2;i<=n;i+=2)
			a[i] = ++now;
		printf("%d", a[1]);
		for(i=2;i<=n;i++)
			printf(" %d", a[i]);
		printf("\n");
	}
	return 0;
}