Description
给出一整数 n n ,考虑以下四条线段上的个整点:
1. 0≤x<n,y=0 0 ≤ x < n , y = 0
2. 0≤x<n,y=n−1 0 ≤ x < n , y = n − 1
3. x=0,0≤y<n x = 0 , 0 ≤ y < n
4. x=n−1,0≤y<n x = n − 1 , 0 ≤ y < n
要求构造 n n 条不平行于坐标轴的直线,使得每条直线经过这个整点中的两个且这些直线的交点尽可能多,从 (0,0) ( 0 , 0 ) 开始逆时针给这 4n−4 4 n − 4 个整点编号为 0,1,...,4n−5 0 , 1 , . . . , 4 n − 5 ,输出每条直线经过的两个整点的编号
Input
第一行一整数 T T 表示用例组数,每组用例输入一整数
Output
输出 2n 2 n 个整数表示这 n n 条直线经过的点的编号
Sample Input
3
2
3
4
Sample Output
0 2 1 3
1 4 2 5 3 6
0 6 1 9 3 8 4 10
Solution
构造题,以点连向 n+i n + i 构造 n−1 n − 1 条直线 (0≤i<n−1) ( 0 ≤ i < n − 1 ) ,再从右下角 n−1 n − 1 连向左上角 3⋅(n−1) 3 ⋅ ( n − 1 ) 旁边的 3n−4 3 n − 4 或 3n−2 3 n − 2 即可,可以证明任意三点不共线,这样的 n n 条直线的交点必然最多,注意时特判
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
vector<int>ans;
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
if(n==2)printf("0 2 1 3\n");
else
{
for(int i=0;i<n-1;i++)printf("%d %d ",i,n+i);
printf("%d %d\n",n-1,3*(n-1)-1);
}
}
return 0;
}