I - Magic Points (2019省赛训练-4)

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

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

  • 0≤x<n0≤x<n and y=n−1y=n−1;

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

  • x=n−1x=n−1 and 0≤y<n0≤y<n.

It's easy to discover that there are (4n−4)(4n−4) magic points in total. These magic points are numbered from 00 to 4n−54n−5 in counter-clockwise order starting from (0,0)(0,0).

DreamGrid can create nn magic lines from these magic points. Each magic line passes through exactly two magic points but cannot be parallel to the line x=0x=0 or y=0y=0 (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 TT (about 100), indicating the number of test cases. For each test case, there is only one integer nn (2≤n≤10002≤n≤1000).

Output

For each case output 2n2n integers p1,p2,…,p2np1,p2,…,p2n in one line separated by one space, indicating that in your answer, point p2k−1p2k−1 and point p2kp2k is connected by a line for all 1≤k≤n1≤k≤n.

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

题意:给出n,代表有每个边有n个点,一共有4n-4个点,标号是从左下角0开始逆时针到4n-5,要求要连n条线,每条线只有两个点,问这n条线交点最多时,是连的哪n对点。

思路:让0和n,1和n-1,……先连n-1条边,因为这样总会保证有不重复的交点,本来想着让最左上角和右下角连,但是一直wrong,最后试了一下最右下角和左上角右边位置上连(即n-1和3n-4),就对了~~最后特判一下2.

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <vector>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=3e5+10;
int main()
{
    ll t,i,j,a,b,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        if(n==2)
            cout<<"0 2 1 3"<<endl;
        else
        {
            cout<<"0 "<<n;//只是因为格式而单列出来
            for(i=1;i<=n-2;i++)
                cout<<" "<<i<<" "<<n+i;
            cout<<" "<<n-1<<" "<<3*n-4<<endl;
        }
    }
    return 0;
}

 

相关文章: