Bounty Hunter Jeong-eun
Time limit1sMemory limit256 MB
A ship visits every planet sorted by x on an outward and a return monotone leg with minimum total Euclidean length.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Geometry
- Solved
- No attempts yet
Problem
Jeong-eun is a bounty hunter chasing a criminal. Jeong-eun flies the ship Galchi II and has to visit all planets scattered over a two dimensional plane, then return to the starting planet. The starting planet is the one with the smallest coordinate. Jeong-eun is poor but extravagant and wants to keep enough money for expensive beef, so the total travel distance has to be as small as possible.
Jeong-eun is also chasing the crime syndicate CTP, and restricts the route to avoid being spotted. From the starting planet to the planet with the largest coordinate, the ship moves only in increasing order of . Coming back from there to the starting planet, it moves only in decreasing order of . The two legs together visit every planet exactly once. The planet with the smallest coordinate and the planet with the largest coordinate are the turning points shared by both legs, and every other planet belongs to exactly one leg. When the route goes from the left planet to the right planet and straight back.
The distance between two planets is the Euclidean distance. Find the shortest total length among the routes that satisfy the rule.
Input
The first line contains the number of test cases ().
The first line of each test case contains the number of planets (). Each of the next lines contains the coordinates and () of one planet, separated by a space.
All coordinates are integers. Within one test case the coordinates are distinct, and the planets are given in increasing order of .
Output
For each test case, print the length of the shortest route on its own line.
Round the length at the fourth decimal place and print exactly four digits after the decimal point. Pad with zeros even when the value is an integer, as in 400.0000. The output is compared as an exact string.