Connection Status:
Competition Arena > FallingPoints
SRM 431 · 2008-12-23 · by Gluk · Simple Math
Class Name: FallingPoints
Return Type: double[]
Method Name: getHeights
Arg Types: (vector<int>, int)
Problem Statement

Problem Statement

You are given a int[] X containing the x-coordinates of several points. Each point starts at an infinitely high y-coordinate. Starting with the first point, each point falls down until it is either a distance of R away from a previously fallen point or it reaches y = 0. Each point (after the first point) will start falling only when the previous one stops. Return a double[], where the i-th element is the final y-coordinate of the i-th point.

Notes

  • Each element of your return value must have an absolute or relative error less than 1e-9.

Constraints

  • X will contain between 1 and 50 elements, inclusive.
  • All elements of X will be between 0 and 1,000, inclusive.
  • R will be between 1 and 1,000, inclusive.
Examples
0)
{0}
10
Returns: {0.0 }

There is only one point and it will just fall down.

1)
{1,100}
10
Returns: {0.0, 0.0 }

Both points will fall down.

2)
{0,9}
10
Returns: {0.0, 4.358898943540674 }

The first point falls down. The second point stops at a distance of 10 away from the first point.

3)
{0,9,19}
10
Returns: {0.0, 4.358898943540674, 4.358898943540674 }
4)
{0,6,13,23,33,42,51}
10
Returns: {0.0, 8.0, 15.14142842854285, 15.14142842854285, 15.14142842854285, 19.500327372083525, 23.8592263156242 }

Submissions are judged against all 216 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class FallingPoints with a public method vector<double> getHeights(vector<int> X, int R) · 216 test cases · 2 s / 256 MB per case

Submitting as anonymous