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. Imagine a system with some unknown acceleration of gravity.
你可能还记得一个叫做“不可思议的机器”的古老电脑游戏。在这个游戏中,你可以模拟一些简单的过程,如小球下落,激光射击,或猫追老鼠。此外,你还能观测到不同的重力加速度。想象一下,这些不同的重力加速度对一个系统的影响吧。
There are N balls, each fixed initially at some height above the ground.You are given a int[] height, where the i-th element is the height of the i-th ball above the ground.
这里有为N个球,每个球都固定在一个给定初始值的高度上。给你一个整型数组(int[] height)来储存一组记录高度的数据,每个值及指代一个高度。
At time 0, the first ball is set loose and it starts falling. When it reaches the ground, the second ball is instantly set loose, and so on. This continues until the last ball reaches the ground at time T. Return the acceleration of gravity in this system.
松开第一个球,并开始计时,然后球开始自由下落。当它落到地面上时,第二个球立即开始下落,依次反复。直到在时间为T时,最后一个球落地为止。返回重力加速度的值。
Neglect air resistance and any other resisting factors. The distance d travelled by an object falling for time t with no initial velocity in a system with gravitational acceleration g and no resisting factors is equal to d = 0.5 * g * t^2.
忽略空气阻力和其他任何外界因素。物体在没有初速度且仅受重力加速度的作用下,经过时间t时走过的路程记为d,则有如下公式:d = 0.5 *g*t^ 2 。
Definition(定义)
Class(类名): IncredibleMachineEasy
Method(方法): gravitationalAcceleration
Parameters(参数): int[], int
Returns(返回值类型): double
Method signature(方法定义样式): public double gravitationalAcceleration(int[] height, int T)
Notes(备注)
- The returned value must have an absolute or relative error less than 1e-9.
- 返回值必须保证绝对或相对误差小于1e - 9 。
Constraints(限制)
- height will contain between 1 and 50 elements, inclusive.
- 一组高度值限制在1到50个值之间
- Each element of height will be between 1 and 100, inclusive.
- 每个高度值限制在1到100之间
- T will be between 1 and 100, inclusive.
- T限制在1到100之间
Examples(样例)
0)
{16,23,85,3,35,72,96,88,2,14,63}
30
Returns(返回值): 9.803799620759717
That's an acceleration of gravity that might be somewhere on Earth's surface.
这是地球某处的重力加速度的值。
1)
{6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,5}
12
Returns(返回值): 26.73924541044107
And this is likely on Jupiter.
这个值可能出现在木星上。
2)
{8,8}
3
Returns(返回值): 7.111111111111111
That's a light one.
这是一个很小的值。
3)
{3,1,3,1,3}
12
Returns(返回值): 0.7192306901503684
You could nearly fly under such conditions.
在这个条件下,你几乎可以飞起来了。
Source code(源代码)