Pulse Nova
Time limit20sMemory limit256 MB
Place a circle of radius R so that the total length of the given lines' segments inside the circle is maximized.
- Level
Hard8 of 10
- Topics
- Geometry, Brute force
- Solved
- No attempts yet
Statement
Mr.Panda is playing Watcher of Samsara, a tower defense game. At the start of the game, every player can freely pick their first hero from a hero pool that the game system generates at random. Mr.Panda always picks Leshrac, because of the character's ultimate skill, Pulse Nova.
Pulse Nova sends out a wave of damaging energy around Leshrac once per second, hitting every nearby enemy unit. This skill gave Mr.Panda an idea for a geometry problem.
There are straight lines on the 2D plane. The -th line passes through two integer points and . Place a circle with radius exactly on the plane. For each given line, a segment of that line may lie inside the circle. Find a position for the circle that maximizes the total length of all these segments inside the circle.
Input
The first line contains (), the number of test cases. Each test case follows.
The first line of each test case contains two integers () and (), the number of lines and the radius of the circle.
The next lines each contain four integers. On the -th of these lines, the first two integers are the coordinates of , and the last two are the coordinates of . , and the absolute value of every coordinate is at most 1000.
The sum of over all test cases is at most 100.
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1, and is the maximum total length inside the circle. An answer is correct if its absolute or relative error is within .
Hint
In the first sample, placing the center at gives a total length of 8 inside the circle.
In the second sample, placing the center at gives a total length of inside the circle.
