Town Square
InterviewTime limit1sMemory limit128 MB
Given four statue points, find the side length of the largest square whose four sides each sit exactly 5 feet from one distinct statue.
- Level
Medium6 of 10
- Topics
- Geometry, Brute force, Implementation, Math
- Solved
- No attempts yet
Problem
Felix J. Humble, a wealthy resident of a small town, has erected four statues of himself in a public park that he owns. To keep the statues safe, he wants to build a square fence around them, and for aesthetic reasons the fence must satisfy all of the following conditions:
- The enclosed region is a square.
- Each statue is exactly 5 feet from its nearest side of the fence.
- No two statues have the same nearest side.
The square may be built at any orientation; its sides do not have to be parallel to the coordinate axes. Given the positions of the four statues, decide whether such a fence can be built and, if so, how long each side must be.
Input
The first line contains an integer , the number of test cases.
Each of the next lines describes one test case with eight integers: the and coordinates of the first, second, third, and fourth statue, in that order. Every coordinate is measured in feet and satisfies . Within a test case, no two statues share the same location.
Output
For each test case, print a single line.
If a valid square fence exists, print Case k: L, where is the test case number (starting at 1) and is the side length of the largest valid square, rounded to the nearest hundredth of a foot and shown with exactly two digits after the decimal point.
If no valid square fence exists, print Case k: no solution.