Hovering Hornet
Time limit1sMemory limit512 MB
Expected number of spots on a die visible from a random point in its box, counting a spot only when the segment to the viewer misses the die.
- Level
Medium6 of 10
- Topics
- Geometry, Probability, Math
- Solved
- No attempts yet
Problem
You have managed to trap a hornet inside a box lying on top of your dining table. Your playing dice is trapped inside as well, so you cannot retrieve it and continue your game of Monopoly without risking the hornet's wrath. Instead, you pass the time by computing the expected number of spots on the dice visible to the hornet.
The hornet, the dice and the box are located in the standard three-dimensional coordinate system, with the coordinate growing eastwards, the coordinate growing northwards and the coordinate growing upwards. The surface of the table is the plane.

Perspective and birds-eye view of the second example input
The dice is a cube resting on the table with the center of its bottom side exactly at the origin, so the coordinates of its two opposite corners are and . The top side of the dice has spots, the south side spot, the east side spots, the north side spots, the west side spots and the bottom side spots. The bottom spots are invisible and irrelevant.
The box is a cube also resting on the table, with the dice in its interior. The box is given by the coordinates of its bottom side, a square.
The hornet hovers at a uniformly random point of the (continuous) space inside the box that is not occupied by the dice. Compute the expected number of spots visible to the hornet. The dice is opaque, so the hornet sees a spot only if the segment connecting the center of that spot to the location of the hornet does not intersect the interior of the dice.
Input
The input consists of lines. The -th line contains two floating-point numbers and (), the coordinates of the -th corner of the bottom side of the box in the plane. The corners are given in counterclockwise order and they describe a square whose side length is exactly .
The box fully contains the dice. The surfaces of the box and the dice neither intersect nor touch, except along the bottom sides.
Output
Print the expected number of visible spots on one line, rounded to six digits after the decimal point. Always print all six digits. For example, if the answer is exactly , print 11.250000.