Hell of Optimizing Geometric Construction

시간 제한2초메모리 제한2048 MB

요약
각 점의 유일한 최근접 이웃이 n개 점을 한 바퀴 도는 순환이 되도록 정수 좌표 n개를 구성한다.
난이도

어려움10점 중 9점

유형
기하, 구현, 완전 탐색, 수학
정답자
아직 제출이 없습니다

문제

One day, dnialh mentioned that optimizing geometric construction perfectly is not possible. Oh, very well. You will see about that.

You are given a positive integer nn such that 2≤n≤1,3202 \le n \le 1\\,320. Please find a sequence of nn points on the plane, X_1,X_2,⋯ ,X_nX\_1,X\_2,\cdots,X\_n, satisfying the following constraints.

  • The coordinates of each point are integers in the range \[−1,000,1,000]\[-1\\,000,1\\,000].
  • No two points share the same coordinates.
  • For each 1≤i≤n1 \le i \le n, the closest point to X_iX\_i other than X_iX\_i itself is unique. Let the index of this unique point be f(i)f(i).
  • Let pp be a sequence of nn integers defined by p_1=1p\_1=1 and p_i+1=f(p_i)p\_{i+1}=f(p\_i) for 1≤i<n1 \le i < n. Then, pp is a permutation of 1,2,⋯ ,n1,2,\cdots,n.

It is proven that such a sequence of points exists under the constraints of this task.

입력

A positive integer nn is given on one line. (2≤n≤1,3202 \le n \le 1\\,320)

출력

Output nn lines. The ii-th line must contain x_ix\_i and y_iy\_i, the coordinates of X_iX\_i, separated by a space. (−1,000≤x_i,y_i≤1,000-1\\,000 \le x\_i,y\_i \le 1\\,000)

힌트

In the samples, n=4n=4 and X=\[(−2,−2),(1,2),(−2,2),(2,1)]X=\[(-2,-2),(1,2),(-2,2),(2,1)].

Here, f(i)f(i) is determined as follows.

  • Other than X_1X\_1, the unique closest point to X_1X\_1 is X_3X\_3. Therefore, f(1)=3f(1)=3.
  • Other than X_2X\_2, the unique closest point to X_2X\_2 is X_4X\_4. Therefore, f(2)=4f(2)=4.
  • Other than X_3X\_3, the unique closest point to X_3X\_3 is X_2X\_2. Therefore, f(3)=2f(3)=2.
  • Other than X_4X\_4, the unique closest point to X_4X\_4 is X_2X\_2. Therefore, f(4)=2f(4)=2.

Now, one can manually verify that the resultant sequence p=\[1,3,2,4]p=\[1,3,2,4] is a permutation of 1,2,3,41,2,3,4. Therefore, the sequence of points satisfies the constraints.

예제1

  1. 예제 1

    입력
    4
    
    예상 출력
    -2 -2
    1 2
    -2 2
    2 1