Constellation
SRM 595 · 2013-06-25 · by cgy4ever
Problem Statement
You are given
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.
Notes
- 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.
Constraints
- 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.
{0,0,1}
{0,1,0}
{500,500,500}
Returns: 0.0625
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.
{0,1,0,1}
{0,0,1,1}
{1000,1000,400,800}
Returns: 0.6000000000000001
Stars 0 and 1 are always visible, thus there are four possible cases: 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. Thus, the answer is 0.32 * 1 + 0.48 * 0.5 + 0.08 * 0.5 + 0.12 * 0 = 0.6.
{-1,-1,-1,0,0,0,1,1,1}
{-1,0,1,-1,0,1,-1,0,1}
{500,500,500,500,500,500,500,500,500}
Returns: 1.9375
{0,0,1,2,2}
{0,1,2,1,0}
{1000,500,200,500,1000}
Returns: 1.3
{1,5,5,8,2,6,9}
{3,6,4,2,5,7,9}
{100,400,200,1000,400,900,600}
Returns: 12.888936
Submissions are judged against all 87 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Constellation with a public method double expectation(vector<int> x, vector<int> y, vector<int> prob) · 87 test cases · 2 s / 256 MB per case