Pyramid Guards
Time limit1sMemory limit128 MB
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 cubits long and its height is 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 , , , and , with and .
A guard starts on one of the four slant edges at height (measured vertically from the ground). The next three values , , are the heights at which it crosses the other three slant edges, in the order it visits them. 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.