ZOJ 4032 Magic Points(计算几何+构造)

85 篇文章 0 订阅
15 篇文章 0 订阅

Description

给出一整数 n n ,考虑以下四条线段上的4n4个整点:

1. 0x<n,y=0 0 ≤ x < n , y = 0

2. 0x<n,y=n1 0 ≤ x < n , y = n − 1

3. x=0,0y<n x = 0 , 0 ≤ y < n

4. x=n1,0y<n x = n − 1 , 0 ≤ y < n

要求构造 n n 条不平行于坐标轴的直线,使得每条直线经过这4n4个整点中的两个且这些直线的交点尽可能多,从 (0,0) ( 0 , 0 ) 开始逆时针给这 4n4 4 n − 4 个整点编号为 0,1,...,4n5 0 , 1 , . . . , 4 n − 5 ,输出每条直线经过的两个整点的编号

Input

第一行一整数 T T 表示用例组数,每组用例输入一整数n(2n1000)

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

构造题,以i点连向 n+i n + i 构造 n1 n − 1 条直线 (0i<n1) ( 0 ≤ i < n − 1 ) ,再从右下角 n1 n − 1 连向左上角 3(n1) 3 ⋅ ( n − 1 ) 旁边的 3n4 3 n − 4 3n2 3 n − 2 即可,可以证明任意三点不共线,这样的 n n 条直线的交点必然最多,注意n=2时特判

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值