This page is still under construction.

Parts of this page are still being built. What you see may change.

Pyramid Guards

Time limit1sMemory limit128 MB

Summary
Two guards walk opposite closed quadrilateral loops on a square pyramid's surface; find the minimum straight-line distance between them while they share a face.
Level

Hard8 of 10

Topics
Geometry, Math, Simulation, Implementation
Solved
No attempts yet

Problem

The Great Pyramid of Giza is Egypt's most famous tourist attraction. Less well known is that building it was only half of the job — the other half was security. Once the Pyramid was finished, some people decided that the Pharaoh's remains did not really need all of the treasures buried with them and wanted to help themselves. To keep the Pyramid from being robbed, two guards continuously patrolled it, walking in opposite directions.

To help plan the patrol, your task is to find the smallest distance at which the two guards ever see each other.

The Great Pyramid is a geometric pyramid with a square base whose apex sits directly above the centre of the base. Its base edge is 440440 cubits long and its height is 280280 cubits. (The cubit was a unit of length used in ancient Egypt.)

Both guards move along the surface of the pyramid, one clockwise and the other counter-clockwise around the apex. Each guard's route is a closed quadrilateral of four straight segments, each segment lying on one of the four triangular faces. As soon as a guard returns to its starting point, it sets off again along exactly the same route.

Input

The input contains several test cases. Each test case has two lines, one per guard. Each line holds five integers H1H_1, H2H_2, H3H_3, H4H_4 and TT, with 0≤Hi<2800 \le H_i < 280 and 1≤T≤1201 \le T \le 120.

A guard starts on one of the four slant edges at height H1H_1 (measured vertically from the ground). The next three values H2H_2, H3H_3, H4H_4 are the heights at which it crosses the other three slant edges, in the order it visits them. TT is the number of minutes the guard takes to return to its starting point and begin another loop.

The two guards start at the same moment on opposite slant edges and walk in opposite directions. Each moves at a constant speed, and you may assume the patrol continues indefinitely.

The input ends with a line of five zeros, which must not be processed.

Output

For each test case, output the smallest distance ever separating the two guards, considering only the moments when they can actually see each other — that is, when both stand on the same face or edge of the pyramid. Give the distance in cubits, rounded to exactly three digits after the decimal point.

Examples1

  1. Example 1

    Input
    0 0 0 0 20
    0 0 0 0 17
    100 200 100 200 50
    50 150 50 150 60
    0 0 0 0 0
    
    Expected output
    0.000
    44.481