PROBLEM STATEMENT
There is a laser cannon at coordinates (0, 0) on the cartesian plane. There are also several
targets on the plane. Each target is a vertical line segment, and the endpoints of the i-th target
are at coordinates (x[i], y1[i]) and (x[i], y2[i]). A random angle between -Pi/2 and Pi/2,
inclusive, is chosen, and a single shot is fired. The angle -Pi/2 is straight down vertically, 0
is straight to the right horizontally, and Pi/2 is straight up vertically. A shot is a straight
ray of infinite length starting from the point (0, 0). A shot hits a target if there is a common
point between them. Return the expected number of targets that will be hit by the single shot.
Hitting a target doesn't change the direction of the laser shot.
DEFINITION
Class:LaserShooting
Method:numberOfHits
Parameters:vector , vector , vector
Returns:double
Method signature:double numberOfHits(vector x, vector y1, vector y2)
NOTES
-A return value with either an absolute or relative error of less than 1.0e-9 is considered correct.
CONSTRAINTS
-x will contain between 1 and 50 elements, inclusive.
-All elements of x will be distinct.
-x, y1 and y2 will contain the same number of elements.
-Each element of x will be between 1 and 1,000, inclusive.
-Each element of y1 and y2 will be between -1,000 and 1,000, inclusive.
-All targets will have positive lengths.
EXAMPLES
0)
{1}
{-1}
{1}
Returns: 0.5
The only one target will be hit with probability 1/2.
1)
{1,2}
{-1,-2}
{1,2}
Returns: 1.0
Both targets will be hit with probability 1/2.
2)
{3,4,7,1}
{1,2,3,4}
{4,3,2,1}
Returns: 0.4623163952488826
3)
{134,298,151,942}
{-753,-76,19,568}
{440,689,-39,672}
Returns: 1.444210260641501
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.