National Olympiad in Informatics, China, 2005
Li Zhe really really likes his lemon tree, especially on silent nights. When the sky has a crescent moon gently casting light onto the scenery on earth, he feels the need to sit leisurely under the lemon tree which he had planted with his own hands, pondering the philosophies of life.
Li Zhe is a child who enjoys thinking. When he noticed that the shadow casted by the moonlight hitting the lemon tree is extra clear on the ground, he immediately comes up with a question: how large is the area of the tree's shadow?
Li Zhe knows that it is very difficult to directly measure area. Since he is very familiar with the shape of the lemon tree, he would like to use a geometrical method to calculate it. Thus, he has come up with a simplified method.
Li Zhe has split the entire lemon tree into layers, labeled from bottom to top. From layer to layer , each layer is disk-shaped (*), with the exception of layer (the uppermost layer), which is conical. Regarding the disks, the upper and lower surfaces are parallel to each other. Regarding any two neighboring disks, the bottom surface of the upper disk is always completely touching the top surface of the lower disk, and vice versa. The bottom surface of the cone at layer (the uppermost layer) is the top surface of the disk at layer . The circular centers of all of the surfaces (including the treetop) are aligned along a straight line that is perpendicular to the ground. Li Zhe knows that the heights of all the layers are , that the distance from the bottom surface of layer to the ground is , and that the radius of the bottom surface of each layer is . Li Zhe has used a familiar method to determine the angle of the moonlight's rays against the surface of the ground.
Figure 1. Cross-section of the lemon tree
Figure 2. Depiction of moonlight ray angles
To simplify calculations, assume that light rays are parallel to each other, the ground is perfectly level, and the area of the shadow produced by the tree trunk is negligible. Li Zhe obviously knows how to find the answer, but he wishes for you to also try your hands.
Input Specification
Line of input contains the integer and the real number ,
representing the number of layers in the lemon tree and the angle with
which the moonlight strikes the ground.
Line contains real numbers ,
representing the heights of all the layers.
Line contains real numbers ,
representing the radii of the bottom surfaces of all the layers.
Adjacent values on the same line in the input will always be separated
by a single space.
Real values in the input will have between and significant digits,
inclusive.
Output Specification
The output should contain real number – the area of the tree's shadow, rounded and displayed to two places after the decimal.
Sample Input
2 0.7853981633
10.0 10.00 10.00
4.00 5.00
Sample Output
171.97
Constraints
; ; ; .
In test cases worth of points, .
In test cases worth of points, .
In test cases worth of points, .
In test cases worth of points, .
* Note from translator: Layers to are more accurately described as truncated cone-shaped.
Problem translated to English by .
Comments
What am I missing from my program? Is my angle calculation correct?
Your program handles the angle correctly. You did wrong in the area calculation.
Each (except the last) layer of the tree is truncated cone-shaped. A possible shape of the tree's shadow may look like this:
To solve this problem, you need to find the area of the shaded region, which can be done analytically using the scan-line algorithm or using a numerical integration method like the Simpson's rule. The implementation is left as an exercise for you.
Edit 2021-01-30: additional test cases are added to the problem and numerical solutions no longer pass.
Is the problem accuracy now or am I just completely off?