| ||Fox Ciel has a map of the night sky.
On this map she found a constellation that consists of n stars, numbered 0 through n-1 in no particular order.|
You are given ints x, y, and prob.
For each i, star i is located at coordinates (x[i],y[i]) on the map.
The probability that star i will be visible when Ciel looks at the sky is prob[i]/1000.
In the evening Ciel is going to take a look at the night sky.
She will find the constellation in the sky, and mark all the visible stars on her map.
She will then compute the area of the convex hull of the visible stars.
Compute and return the expected value of that area.
|Parameters:||int, int, int|
|Method signature:||double expectation(int x, int y, int prob)|
|(be sure your method is public)|
|-||The events that represent the visibility of individual stars are mutually independent. Thus you may assume that the visibility of each star was independently generated at random with the given probability, just before Ciel looked at the sky.|
|-||Whenever there is a line that contains all the visible stars, the area of their convex hull is 0.|
|-||Return values with absolute or relative error at most 1e-9 will be accepted as correct.|
|-||x will contain between 3 and 50 elements, inclusive.|
|-||x, y and prob will contain same number of elements.|
|-||Each element in x will be between -100 and 100, inclusive.|
|-||Each element in y will be between -100 and 100, inclusive.|
|-||Each element in prob will be between 1 and 1,000, inclusive.|
|-||There will be no two stars at the same position.|
|We have 3 points (0,0), (0,1), (1,0), all of them have 50% probability to be visible. We have 0.5^3 probability to see all 3 stars, and the area will be 0.5, in all other cases, the area will be 0. So the expectation is 0.5^4 = 0.0625.|
|Stars 0 and 1 are always visible, thus there are four possible cases:
Thus, the answer is 0.32 * 1 + 0.48 * 0.5 + 0.08 * 0.5 + 0.12 * 0 = 0.6.
- All four stars are visible with probability 0.4 * 0.8 = 0.32, and in that case the area is 1.
- With probability (1-0.4)*0.8 = 0.48 star 3 is the only invisible star, and the area is 0.5.
- With probability 0.4*(1-0.8) = 0.08 star 2 is the only invisible star, and the area is 0.5.
- Finally, with probability (1-0.4)*(1-0.8) = 0.12 only stars 0 and 1 are visible, and the area is 0.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.