ZOJ 4032 Magic Points

Magic Points

Time Limit: 1 Second       Memory Limit: 65536 KB       Special Judge

Given an integer , we say a point  on a 2D plane is a magic point, if and only if both  and  are integers, and exactly one of the following conditions is satisfied:

  •  0<=x<n and y=0;

  •  0<=x<n and y=n-1;

  •  x=0 and 0<=y<n;

  •  x=n-1 and 0<=y<n.

It's easy to discover that there are  magic points in total. These magic points are numbered from  to  in counter-clockwise order starting from .

DreamGrid can create  magic lines from these magic points. Each magic line passes through exactly two magic points but cannot be parallel to the line  or  (that is to say, the coordinate axes).

The intersections of the magic lines are called dream points, and for some reason, DreamGrid would like to make as many dream points as possible. Can you tell him how to create these magic lines?

Input

There are multiple test cases. The first line of input contains an integer  (about 100), indicating the number of test cases. For each test case, there is only one integer  ().

Output

For each case output  integers  in one line separated by one space, indicating that in your answer, point  and point  is connected by a line for all .

If there are multiple answers, you can print any of them.

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
Hint

The sample test cases are shown as follow:


Author:  ZHOU, Yuchen
Source:  The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple

题意:

给4*n-4个点每个点按一定的规律排列(这里不予给出),求一个方案对这些点画n条线,这些线段不能平行坐标轴,每条线必须恰好经过2个点,且要保证线与线相交的点数尽可能的多。

思路:

先这样画n-1条线:

0→n,1→n+1,2→n+2,3→n+3...i→n+i

之后找一条与之前斜率不等的直线,且要保证不会经过之前的交点。

奇数时可以选择3*n-2,3*n-4;偶数的时候就就要另外重新选择一条边,因为3*n-2,3*n-4和之前一条线段平行了。

示例程序

当时AC的做法和这思路类似,就是我没画0→n,无论奇数还是偶数我都画的0,3*n-4,n-1,4*n-5。

#include <bits/stdc++.h>
#define LDQ 1000000000
#define QAQ 0x3f3f3f3f
#define PI 3.14159265358979323846
using namespace std;
int main()
{
    int t,n,i;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        if(n==2)
        {
            puts("0 2 1 3");
        }
        else
        {
            printf("%d %d %d %d",0,3*n-4,n-1,4*n-5);
            for(i=1;n-2>=i;i++)
            {
                printf(" %d %d",i,i+n-1);
            }
            printf("\n");
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值