Carl's Vacation
Time limit1sMemory limit1024 MB
Find the shortest walk between the apexes of two right square pyramids, moving only on their faces and the ground plane.
- Level
Hard8 of 10
- Topics
- Geometry, Shortest path, Math
- Solved
- No attempts yet
Problem
Carl the ant is back! After winding through meandering paths (Problem A, 2004 World Finals) and wandering over octahedrons (Problem C, 2009 World Finals), it is time for a little vacation. Time to see the sights! And where better to see the sights than at the tips of tall structures like pyramids? And where better to see tall pyramids than Egypt? (This is so exciting!!!!)
After taking in the view from the tip of one pyramid, Carl wants to go to the tip of another. Ants do not handle the hot sun well, so he wants the minimum distance between the tips of the two pyramids. Carl can only walk on the surfaces of the pyramids and on the plane the pyramids sit upon. Each pyramid is a right square pyramid, meaning the apex lies directly above the center of a square base.

Figure 1: Illustration of two pyramids corresponding to Sample Input 1. The black line shows the shortest path between their apexes.
Input
The first line contains five integers , , , , . The points and define an edge of the first pyramid, with the body of the pyramid to the left of the directed vector from to . is the height of the pyramid. The second line describes the second pyramid in the same format. The bases of the two pyramids have an intersection of area 0.
Constraints: , , .
Output
Output the minimum distance Carl travels between the tips of the two pyramids. An absolute or relative error of at most is accepted.