题干:

 

解题报告:

想到了,这样绕圈构造。但是这样有个问题,最后一个点如何构造。

刚开始想的是n=奇数  ,  就8 10 这样的连一条,n=偶数  就8 11 这样的连一条,随便构造一下就行,但是发现这样好像不行。所以改了构造方法

 

大概长这样,就是交叉着连,然后如果n=偶数,那会剩下两条边的空闲,那就先2,4这样连一条,3,7这样连一条。

如果n=奇数,那就剩下一条边的空闲,那就直接3,7这样就行了。

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;

int n;
int main()
{
	int t,q,i,j,k,cnt,a1,b1,a2,b2;
	cin>>t;
	for(;t;t--){
		scanf("%d",&n);
		if(n==2) 
		{puts("0 2 1 3"); continue;}
		if(n%2 == 1) {
			int x = 0,y = 2*n-2;
			for(int i = 1; i<n; i+=2) {
				printf("%d %d ",x,y-1);
				printf("%d %d ",x+1,y);
				x+=2;y-=2;
			}
//			printf("***");
			printf("%d %d\n",n-1,2*n-1);					
		}
		else {
			int x = 0,y = 2*n-2;
			for(int i = 1; i<=n-2; i+=2) {
				printf("%d %d ",x,y-1);
				printf("%d %d ",x+1,y);
				x+=2;y-=2;
			}
			printf("%d %d ",n-2,n);				
			printf("%d %d\n",n-1,2*n-1);
			
		}
	}

	return 0;
}