Given N blue points and 2N red points in general position, build the particular non-crossing perfect matching prescribed by the paper's recursive angular-sweep Solve/Attach procedure.
Hard9Divide and conquerGeometrySortingRecursionNo attempts yetTime limit2sMemory limit512 MBA precision measurement company bought several devices that measure the movement of a distant object with a laser and installed them at different places. Every device carries two laser sensors and one sensor measures one object, so a single device measures two objects at the same time. Laser beams sent from two different devices interfere with each other where they meet, and that interference produces measurement errors, so the beams are arranged so that they never cross.
Draw every installed device as a blue point of the plane and every measured object as a red point. The task becomes the following.
The plane holds N blue points and 2N red points. Call a set of segments a linking when it satisfies all three conditions.

Part (A) of the figure holds three blue points and six red points. Blue point 1 is joined to red points 1 and 4, blue point 2 to red points 2 and 5, blue point 3 to red points 3 and 6, and no two segments cross, so (A) is a linking. Part (B) is another linking of the same points, so one input can admit several linkings. In part (C) the segment from blue point 1 to red point 3 crosses the segment from blue point 3 to red point 2, so (C) is not a linking.
One input can admit several linkings, so print the one that the procedure in the output section builds.
The first line holds the number of blue points N (1≤N≤1,000). The i-th of the next N lines holds the x coordinate and the y coordinate of blue point i. The j-th of the following 2N lines holds the x coordinate and the y coordinate of red point j. Every coordinate is an integer between −108 and 108. No three of the given points lie on one line.
Print N lines. Line i holds the numbers of the two red points joined to blue point i, the smaller number first, separated by one space.
Several linkings can exist, so print the one that the procedure below builds. The procedure always finds the index it asks for, and the linking it builds always satisfies the three conditions.
Give every blue point the value 2 and every red point the value −1, and let the value of a set of points be the sum of the values of its points. The 3N given points have value 0. Run Solve on all 3N given points.
Solve(S), where the value of S is 0:
Attach(T; c; p), where T is not empty and has value −1, the blue point c still needs one red point, and p is a point outside T: