#P4207. The Lemon Tree Shadow
The Lemon Tree Shadow
The Lemon Tree Shadow
Li Zhe adores his lemon tree – especially on serene nights when a gentle crescent moon bathes the earth in light. Seated by the lemon tree he planted himself, Li Zhe ponders a curious question: What is the area of the tree’s shadow under the moonlight?
The tree is modeled as a stack of n layers. Layers 1 to n-1 are frustums (truncated cones) while the top layer (n) is a cone. For each frustum, both the lower and upper bases are horizontal circles. In two adjacent frustums the upper base of the lower one coincides with the lower base of the upper one. The cone of the top layer uses as its base the upper base of the (n‑1)th frustum. All the circular bases (and the tree top) have their centers on the same vertical line.
You are given:
- The height h0 of the lowest circular base above the ground,
- The heights of the n layers: h1, h2, …, hn
- The radii of the n lower bases: r1, r2, …, rn. (For layers 1 to n‑1 the top base radius equals the next layer’s lower base radius. The top layer is a cone with apex radius 0.)
- The angle \(\alpha\) (in radians) between the incoming parallel moonlight and the horizontal ground.
The projection of any point \((x,y,z)\) of the tree onto the ground under the parallel light is given by:
[ (x',y') = \Bigl(x - z\cot(\alpha),; y\Bigr), ]
Thus, the shadow of the tree is the union of the projections of all its horizontal circular cross‐sections. Under the assumption that the tree is convex (which is guaranteed by the way its layers are specified and by the condition that the maximum radius occurs at the bottom layer), it can be shown that the shadow is exactly the convex hull of the bottom disk (with center at \((-h_0\cot(\alpha),0)\) and radius \(r_1\)) and the apex of the tree (whose ground projection is \((-T\cot(\alpha),0)\), where \(T = h_0+\sum_{i=1}^{n}h_i\)).
It is known that the convex hull of a disk of radius \(R\) centered at \((0,0)\) and an external point at distance \(d\) from the center (with \(d\ge R\)) is the Minkowski sum of the disk and the segment of length \(d-R\). Its area is given by:
[ A = \pi R^2 + 2R,(d - R), \quad \text{for } d \ge R, \quad \text{and } A = \pi R^2 \text{ if } d \le R. ]
In this problem, take \(R = r_1\) and \(d = (T-h_0)\cot(\alpha)\). Compute and output the shadow area.
Input Format:
n h0 h1 h2 ... hn r1 r2 ... rn α
Here, n (an integer) is the number of layers; h0 and the hi (1 ≤ i ≤ n) are positive real numbers; ri (1 ≤ i ≤ n) are positive real numbers; and \(\alpha\) is given in radians.
Output Format:
A single real number representing the area of the tree's shadow. Your answer is considered correct if its absolute or relative error does not exceed 1e-6.
Note: You may assume that the maximum horizontal cross‐section occurs at the bottom layer so that the convex hull of the projected tree is exactly the convex hull of the bottom disk and the top point.
inputFormat
The first line contains an integer n (number of layers).
The second line contains a real number h0 (height of the bottom disk from the ground).
The third line contains n real numbers: h1, h2, …, hn (the heights of each layer).
The fourth line contains n real numbers: r1, r2, …, rn (the radii of the lower bases of the layers; note that for layers 1 to n-1, the top radius is the next ri, and the top layer is a cone with apex radius 0).
The fifth line contains a real number \(\alpha\) (in radians).
outputFormat
Output a single real number: the area of the tree's shadow. The answer is accepted if the absolute or relative error is at most 1e-6.
sample
1
0
10
5
1.57079632679
78.53981633974483
</p>