Twirling Towards Freedom (Small)
Time limit5sMemory limit512 MB
Each minute you may stay put or rotate 90 degrees clockwise around one of the stars to maximize the distance from the origin after M minutes.
- Level
Medium4 of 10
- Topics
- Brute force, Geometry, BFS
- Solved
- No attempts yet
Problem
"I say we must move forward, not backward; upward, not forward; and always twirling, twirling, twirling towards freedom!"
Kodos, a former candidate for President of the United States.
Kodos comes from the planet Rigel VII. The speech worked on you, so you have decided to twirl toward freedom as well. In this problem, freedom means getting as far from your starting point as you can.
The galaxy is a two-dimensional plane. Your ship starts at the origin , and the galaxy has stars. Every minute you may pick one star and rotate your ship 90 degrees clockwise around that star. You may also stay where you are for that minute.
How far from the origin can the ship be after minutes?

The picture shows the first three rotations of one possible path for the first example. That path is not part of an optimal plan.
Input
The first line has one integer , the number of test cases. Each test case begins with a line holding and a line holding . The next lines each hold two integers and , the position of the -th star.
Limits
- No two stars are at the same position.
- A star may be at the origin.
Output
For each test case, print one line of the form Case #x: D, where is the test case number starting from 1 and is the distance from the origin to the best final position. Print rounded to exactly six digits after the decimal point.