Wally World

Time limit1sMemory limit128 MB

Summary
Two points in a plane must meet while a single axis-parallel wall segment blocks the straight path; compute the minimum meeting time.
Level

Medium4 of 10

Topics
Geometry, Math, Shortest path, Implementation
Solved
No attempts yet

Problem

Two star-crossed lovers want to meet. The two lovers stand at distinct points in the plane. They can travel freely except that there is a single wall which cannot be crossed. The wall is a line segment parallel to either the xx or the yy axis. Each lover can move 1 unit in 1 second. How long will it take them to be together if they both choose the best path?

Input

Each test case consists of two lines, each containing four integers. On the first line, the first two integers give the xx and yy coordinates of the first lover, and the next two give the xx and yy coordinates of the second lover. The four integers on the second line give the start and end points of the wall.

In all cases both lovers lie off the (infinite) line containing the wall — that is, the wall extended in both directions. All coordinates are positive and at most 1000010000, and neither lover starts on the wall. The input is terminated by a line containing four zeroes.

Output

For each test case, output the minimum time in seconds for the two lovers to meet. Print the answer to exactly 3 decimal places, with each line in the format:

Case n: t

where nn is the 1-based test-case number and tt is the minimum time.

Examples1

  1. Example 1

    Input
    5 2 7 2
    1 1 1 100
    1 2 3 2
    2 1 2 100
    0 0 0 0
    
    Expected output
    Case 1: 1.000
    Case 2: 1.414