TopCoder problem "IncredibleMachine" used in SRM 440 (Division I Level One)



Problem Statement

    You may remember an old computer game called "The Incredible Machine". It was a game where you could simulate simple processes like balls falling, lasers shooting, or cats pursuing mice. Moreover, you were able to perform these observations with different values for gravitational acceleration.



We are observing a system with some unknown acceleration of gravity. There is a slope which has the form of a polyline with N vertices. Each vertex of the polyline is positioned lower and to the right of the previous one. At time 0, a ball is placed at the first vertex. The ball is small enough to be considered a single point. Assume that there's no friction between the slope and the ball, the ball is absolutely nonelastic, and the direction of its velocity changes instantly at the polyline's vertices. Under these conditions, the ball will follow the polyline without ever losing contact with it. The ball reaches the final vertex at time T.



You are given int[]s x and y, where (x[i], y[i]) are the coordinates of the i-th vertex. Return the gravitational acceleration in this system. A body rolling down an inclined plane of angle alpha (measured between the plane and horizontal direction) under gravitational acceleration g has a constant acceleration of a = g * sin(alpha). The distance d travelled by an object during time t moving with initial velocity v0 and with constant acceleration a is equal to d = v0 * t + 0.5 * a * t^2. The velocity v1 of the object after time t has passed is equal to v1 = v0 + a * t.
 

Definition

    
Class:IncredibleMachine
Method:gravitationalAcceleration
Parameters:int[], int[], int
Returns:double
Method signature:double gravitationalAcceleration(int[] x, int[] y, int T)
(be sure your method is public)
    
 

Notes

-The returned value must have an absolute or relative error less than 1e-9.
 

Constraints

-x will contain between 2 and 50 elements, inclusive.
-Elements of x will be strictly ascending.
-Elements of x will be between 0 and 100, inclusive.
-x and y will contain the same number of elements.
-Elements of y will be strictly descending.
-Elements of y will be between 0 and 100, inclusive.
-T will be between 1 and 100, inclusive.
 

Examples

0)
    
{0,6}
{100,22}
4
Returns: 9.807692307692307
That's an acceleration of gravity that might be somewhere on Earth's surface.
1)
    
{0,26,100}
{50,26,24}
4
Returns: 26.743031720603582
And this is likely on Jupiter.
2)
    
{0,7,8}
{10,6,0}
7
Returns: 1.1076837407708007
Note that in spite of the angle at vertex (7,6), the body won't fly off the slope and will follow the segment (7,6)-(8,0).

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13748&pm=10310

Writer:

gojira_tc

Testers:

PabloGilberto , ivan_metelsky , Vasyl[alphacom]

Problem categories:

Math, Search