TopCoder problem "PuckShot" used in SRM 186 (Division I Level Three)



Problem Statement

    

Warning: Embedded in this problem statement is an image that may not be visible if you are using a plugin. For best results, view this problem in the standard Arena editor.

The left-handed Finnish hockey player Slaapi Shotti has a spectacular move where he fires the puck from the blue line, off the boards, and into the net. The relevant portion of an international hockey rink is shown below.

The rink is 3000 centimeters (cm) wide. The distance between the blue line and the goal line is 1733 cm. Centered on the goal line is the goal itself, which is 183 cm wide and marked with a goalpost at each end. When Slaapi shoots, the puck will travel in a straight line from a given point on the blue line, rebound symmetrically from the right border of the rink, and continue traveling in a straight line. We shall model the puck and the goalposts as infinitesimal points on the ice.

Positioned on the ice are up to nine players, whom we model as line segments that are 50 cm long and parallel to the blue line. Each player must stand on or below the goal line, at least one centimeter above the blue line, and at least one centimeter away from the sides. Players may overlap or coincide. In order for Slaapi to score a goal, the puck may not intersect a player's line segment at any point, including its endpoints. For the purposes of player position as well as puck rebound, you may ignore the curvature of the rink and assume that the boards are perfectly straight, forming a rectangle with the blue line and goal line.

Slaapi must shoot the puck from the point on the blue line whose distance from the left border of the rink is given by the int puckCoord. You are also given two int[]s, xCoords and yCoords. The distance in centimeters of the nth player's midpoint from the left border of the rink is given by the nth element of xCoords, and the distance of his midpoint from the blue line is given by the nth element of yCoords.

Calculate the angle, measured counterclockwise from the blue line, at which Slaapi must shoot the puck so that its point of intersection with the goal line is between the goalposts, inclusively, and as close as possible to the right goalpost. Return your answer in degrees as a double value with an absolute or relative error of 1.0e-9. Return -1.0 if Slaapi cannot score a goal in the prescribed manner. The input is guaranteed to be such that the rightmost gap through which Slaapi can score, if any, is at least 1.0e-6 cm wide at the goal line.

 

Definition

    
Class:PuckShot
Method:caromAngle
Parameters:int, int[], int[]
Returns:double
Method signature:double caromAngle(int puckCoord, int[] xCoords, int[] yCoords)
(be sure your method is public)
    
 

Constraints

-puckCoord is between 1 and 2999, inclusive
-xCoords contains between one and nine elements, inclusive
-yCoords contains the same number of elements as xCoords
-each element of xCoords is between 26 and 2974, inclusive
-each element of yCoords is between 1 and 1733, inclusive
-the input is such that the rightmost gap through which Slaapi can score, if any, is at least 1.0e-6 cm wide at the goal line
 

Examples

0)
    
2833
{1500, 1580}
{1730, 1730}
Returns: 47.022170720170784
Two players are positioned near the goal, one in the center and another by the right goalpost. Between them is a gap that lets Slaapi score a goal. He puts the puck as close to the right goalpost as possible.
1)
    
2833
{2690}
{500}
Returns: 44.88563731851585
A single player not far from the blue line forces Slaapi to put the puck near the left goalpost.
2)
    
2833
{2690, 2676}
{500, 500}
Returns: -1.0
Two players not far from the blue line are completely blocking Slaapi's shot.
3)
    
55
{1479, 1427, 2556, 2834, 2866, 2958, 2763, 2899, 2630}
{1708, 1726, 487, 471, 121, 446, 473, 266, 380}
Returns: 21.706043385046158
4)
    
1809
{1571}
{1730}
Returns: 33.18726534329994
The player's right endpoint is exactly in the way of the right goalpost, so Slaapi must shoot to the left of the player.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=2411

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4750&pm=2411

Writer:

Eeyore

Testers:

lbackstrom , brett1479

Problem categories:

Geometry