Town Square

Interview

Time limit1sMemory limit128 MB

Summary
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:

  1. The enclosed region is a square.
  2. Each statue is exactly 5 feet from its nearest side of the fence.
  3. 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 nn, the number of test cases.

Each of the next nn lines describes one test case with eight integers: the xx and yy coordinates of the first, second, third, and fourth statue, in that order. Every coordinate is measured in feet and satisfies −100≤v≤100-100 \le v \le 100. 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 kk is the test case number (starting at 1) and LL 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.

Examples2

  1. Example 1

    Input
    2
    0 1 1 0 3 4 4 2
    0 1 0 2 0 3 0 4
    
    Expected output
    Case 1: 14.00
    Case 2: no solution
    
  2. Example 2

    Input
    1
    29 -5 -20 3 18 -21 -3 28
    
    Expected output
    Case 1: 59.00