Rockets
Time limit1sMemory limit128 MB
Match the n red points to the n white points with non-crossing segments so the total Euclidean length is minimum, and report the matching.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Divide and conquer, Geometry, Sorting
- Solved
- No attempts yet
Problem
A two dimensional map holds two sets of points each, and . No three points of lie on one line. Surface to surface rockets stand on the points of , and the targets to destroy stand on the points of . A rocket flies only in a straight line, every rocket destroys exactly one target, and every target is hit by exactly one rocket.
No two trajectories may cross. Among the assignments that respect this, find the one whose total flight distance is the smallest. Here is the Euclidean distance between and , and is the target destroyed by rocket . The input guarantees that exactly one of the assignments reaches the smallest total flight distance, so the answer is unique.
Input
The first line contains the size of both and ().
Each of the next lines contains the coordinates and of one point of the map, separated by a single space (). The first of those lines are the points of , the last are the points of . Line holds and line holds (). All points are distinct and no three of them lie on one line.
Output
Print lines. Line contains the index of the target that rocket destroys.