挑战程序设计竞赛3.2例题:Physics Experiment POJ - 3684

Simon is doing a physics experiment with N identical balls with the same radius of R centimeters. Before the experiment, all N balls are fastened within a vertical tube one by one and the lowest point of the lowest ball is H meters above the ground. At beginning of the experiment, (at second 0), the first ball is released and falls down due to the gravity. After that, the balls are released one by one in every second until all balls have been released. When a ball hits the ground, it will bounce back with the same speed as it hits the ground. When two balls hit each other, they with exchange their velocities (both speed and direction).

Simon wants to know where are the N balls after T seconds. Can you help him?

In this problem, you can assume that the gravity is constant: g = 10 m/s2.

Input

The first line of the input contains one integer C (C ≤ 20) indicating the number of test cases. Each of the following lines contains four integers NHRT.
1≤ N ≤ 100.
1≤ H ≤ 10000
1≤ R ≤ 100
1≤ T ≤ 10000

Output

For each test case, your program should output N real numbers indicating the height in meters of the lowest point of each ball separated by a single space in a single line. Each number should be rounded to 2 digit after the decimal point.

Sample Input

2
1 10 10 100
2 10 10 100

Sample Output

4.95
4.95 10.20
我一直以为题目写错了,结果发现这道题有坑(详解见白书相关):
1.球之间是间隔一秒下落的,你的时间可能会出现到了T但是还有球没下落,所以这样的情况直接是H + 2 * R * (i - 1)
2.为啥要排序,答案是因为虽然这道题和ant差不多,碰撞交换可以看成不碰撞,但是因为在上方的球一定时时刻刻在下方球的下方,也就是i+1的球一定高于i,我们这里考虑的是实际的球的编号,上方的球碰到了下方的球,上方的球还是向上,下方的球还是向下,只不过交换了速度罢了(因为能量守恒定律&动量守恒定律),所以题目暗暗的说了输出each ball(所以按照球的顺序(虽然如果output在说明是按照球的顺序或者就说从小到大就好了)输出,也就是从小到大)。
3.为什么答案是算出来的是最后计算的高度tall+2*r*(i - 1)而不是先把H += 2 * r再计算最后的tall,因为其实很简单,当球在碰撞的时候两者虽然交换了速度,但是注意,因为有半径不能看成质点,实际上相当于下方的球上移了2R(因为有半径,实在理解不了画个有半径球碰撞的图,当我们把碰撞时下方的球看成碰撞后上方的球是,实际上上移了2R),上方的球下移了2R,所以下方的球下落的实际高度仍然是H,上升也是一样,如果有三个球,第三个球下落必定要和第一第二碰撞,每次少2mgR的机械能,别看它比第一个高了4R下落,实际上的下落高度也是H,因为他要和1号球2号球都碰一下,每次白白低了2R,所以实际上还是H。

4.然后就是最后坐标的问题,虽然每个球都相当于在高为H的自由落体(虽然下落的高度不同,但是因为会和下方的球碰撞,所以实际做自由落体的高度仍然是H),但是每个球的坐标不一样,比如第二个球就因为占了第一个球的2mgR的便宜,白白因为和球1碰撞高了2R,所以最后结果要加上。

猜你喜欢

转载自www.cnblogs.com/jacobfun/p/12519499.html