Running in the Plane

시간 제한1초메모리 제한1024 MB

요약
격자점 집합이 주어질 때, 원점에서 출발하는 보행이 모든 점을 한 번씩 지나도록 하는 최소 크기의 정수 이동 벡터 집합을 구한다.
난이도

어려움10점 중 9점

유형
수학, 정수론, 기하, 그리디
정답자
아직 제출이 없습니다

문제

You are given a set S=(a_1,b_1),(a_2,b_2),…,(a_n,b_n)S=\\{(a\_1,b\_1) ,(a\_2,b\_2) ,\dots ,(a\_n,b\_n)\\} of nn points in the plane. All coordinates of SS are integers.

A set T=(c_1,d_1),(c_2,d_2),…,(c_m,d_m)T=\\{(c\_1,d\_1) ,(c\_2,d\_2) ,\dots ,(c\_m,d\_m)\\} of mm 2-dimensional vectors is called a good set of SS if it satisfies the following:

  1. There exists a nonempty finite sequence ((x_0,y_0),(x_1,y_1),…,(x_l,y_l))((x\_0,y\_0) ,(x\_1,y\_1) ,\dots ,(x\_l,y\_l)) of points in the plane such that

    1. (x_0,y_0)=(0,0)(x\_0,y\_0) =(0,0).
    2. For all points pp in SS, there exists an integer ii (0≤i≤l0\le i\le l) such that (x_i,y_i)=p(x\_i,y\_i) =p.
    3. For all integers ii (0≤i\<l0\le i\<l), the vector (x_i+1−x_i,y_i+1−y_i)(x\_{i+1}-x\_i,y\_{i+1}-y\_i) is in TT.
  2. For all integers ii (1≤i≤m1\le i\le m), two numbers c_ic\_i and d_id\_i are integers between −1018-10^{18} and 101810^{18} inclusive.

Find any good set of minimum size.

입력

The input consists of multiple test cases. The first line contains an integer QQ — the number of test cases. The description of the test cases follows. For each test case:

  • The first line of the test case contains an integer nn — the number of points in SS.
  • The ii-th of the next nn lines contains two integers a_ia\_i and b_ib\_i — the coordinates of each point in SS.

출력

For each test case:

  • Let T=(c_1,d_1),(c_2,d_2),…,(c_m,d_m)T=\\{(c\_1,d\_1) ,(c\_2,d\_2) ,\dots ,(c\_m,d\_m)\\} be a minimum-size good set of SS.
  • In the first line of the test case, print an integer mm — the number of vectors in TT.
  • In the ii-th of the next mm lines, print two integers c_ic\_i and d_id\_i — the coordinates of each vector.

If there are multiple solutions, print any of them.

It can be proved that, under the constraints of this problem, a good set of SS with size at most 10×n10\times n always exists.

제한

  • 1≤Q≤50,0001\le Q\le 50\\, 000
  • The sum of nn over all test cases does not exceed 10510^5.
  • 2≤n≤1052\le n\le 10^5
  • −108≤a_i,b_i≤108-10^8\le a\_i,b\_i\le 10^8 (1≤i≤n1\le i\le n)
  • (a_i,b_i)≠(a_j,b_j)(a\_i,b\_i)\ne(a\_j,b\_j) (1≤i\<j≤n1\le i\<j\le n)
  • m≥0m\ge 0
  • −1018≤c_i,d_i≤1018-10^{18}\le c\_i,d\_i\le 10^{18} (1≤i≤m1\le i\le m)
  • (c_i,d_i)≠(c_j,d_j)(c\_i,d\_i)\ne(c\_j,d\_j) (1≤i\<j≤m1\le i\<j\le m)

힌트

In the first test case, T=(−10,10)T=\\{(-10,10)\\} is a minimum-size good set of S=(−30,30),(−50,50)S=\\{(-30,30) ,(-50,50)\\}.

We can take a sequence ((0,0),(−10,10),(−20,20),(−30,30)‾,(−40,40),(−50,50)‾)((0,0) ,(-10,10) ,(-20,20) ,\underline{(-30,30)} ,(-40,40) ,\underline{(-50,50)}). Here, the underlined points are in SS.

In the second test case, T=(1,0),(1,1)T=\\{(1,0) ,(1,1)\\} is a minimum-size good set of S=(2,1),(1,0),(4,1)S=\\{(2,1) ,(1,0) ,(4,1)\\}.

We can take a sequence ((0,0),(1,0)‾,(2,1)‾,(3,1),(4,1)‾)((0,0) ,\underline{(1,0)} ,\underline{(2,1)} ,(3,1) ,\underline{(4,1)}).

예제1

  1. 예제 1

    입력
    2
    2
    -30 30
    -50 50
    3
    2 1
    1 0
    4 1
    
    예상 출력
    1
    -10 10
    2
    1 0
    1 1