Patrol Robot

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

요약
일반 위치의 점들이 주어질 때, 오른쪽으로 도는 로봇이 모든 점을 무한히 방문하도록 교차하지 않는 선분을 골라 출력한다.
난이도

어려움10점 중 9점

유형
기하, 분할 정복, 재귀, 정렬
정답자
아직 제출이 없습니다

문제

The Coordinate Control Organization has developed an autonomous robot to patrol NN distinct important locations on a two-dimensional plane. The ii-th location has coordinates (x_i,y_i)(x\_i , y\_i), and it is guaranteed that no three locations lie on a common line.

To help guide the robot, you may paint some line segments on the ground. Each segment must directly connect two important locations, and no two segments may intersect, except possibly at their endpoints.

The robot will begin its patrol at the midpoint of an arbitrary segment, facing towards one of its endpoints. It will move indefinitely according to the following procedure:

  • As long as the robot is in the interior of a segment, it will move forward, towards a segment endpoint.
  • When the robot reaches an important location, it will initially be facing directly away from the segment it just traversed. The robot will turn right/clockwise until its line of vision is aligned with a segment that leads away from the current location. The robot will then begin moving along this new segment.

Your task is to paint the segments in such a way that, no matter where the robot starts, it is guaranteed to visit every important location infinitely often. It can be proven that this is always possible.

입력

The first line of input contains a single integer NN (2≤N≤2,0002 ≤ N ≤ 2\\, 000), the number of important locations.

The next NN lines of input each contain two space-separated integers, x_ix\_i and y_iy\_i (−109≤x_i,y_i≤109−10^9 ≤ x\_i , y\_i ≤ 10^9), the coordinates of the ii-th important location.

It is guaranteed that all NN important locations are distinct and no three lie on a common line.

출력

On the first line, output a positive integer MM, the number of line segments you paint on the ground.

The next MM lines of output should each contain two space-separated integers, u_iu\_i and v_iv\_i (1≤u_i,v_i≤N1 ≤ u\_i , v\_i ≤ N, u_i≠v_iu\_i \ne v\_i), denoting that you paint a line segment between the u_iu\_i-th and v_iv\_i-th important locations.

If there are multiple acceptable answers, output any of them.

예제2

  1. 예제 1

    입력
    4
    0 0
    1 1
    1 2
    2 1
    
    예상 출력
    3
    1 2
    2 3
    2 4
    
  2. 예제 2

    입력
    8
    0 0
    0 3
    1 1
    1 2
    4 1
    4 2
    5 0
    5 3
    
    예상 출력
    9
    1 2
    2 4
    4 8
    8 7
    7 5
    5 1
    3 4
    4 5
    5 6