POJ 3684 Physics Experiment 弹性碰撞

Physics Experiment
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1709   Accepted: 582   Special Judge

Description

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).

POJ 3684 Physics Experiment 弹性碰撞_第1张图片

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

题意:

用N个半径为R厘米的球进行如下实验。

在H米高的位置设置一个圆筒,将球垂直放入(从下向上数第i个球的底端距离地面高度为H + 2R)。实验开始时,最下面的球开始掉落,此后每一秒又有一个球开始掉落。不计空气阻力,并假设球与球或地面间的碰撞是弹性碰撞。

请求出实验开始后T秒钟时每个球底端的高度。假设重力加速度为g = 10m/s2。

分析:

首先考虑一下只有一个球的情形。这时只是单纯的物理问题。从高为H的位置下落的话需要花费的时间是t = 根号下2 * H / g

这样的话,在时刻T时,令k为满足kt <=T的最大整数,那么

(1)y = H – 1/2 * g * (T – kt)的平方 (k是偶数时)

(2)y = H – 1/2 * g * (kt + t – T)的平方 (k是奇数时)

接下来在考虑多球的情形。乍一看,因为多个求之间会有碰撞,必须对物理运动进行模拟,事实上并没有这个必要。与之前的题目”Ants”,蚂蚁在树枝上走的那道题类似。

首先来考虑一下R = 0的情况。如果认为所有的球都是一样的,就可以无视它们的碰撞,视为直接互相穿过继续运动。由于在有碰撞时球的顺序不会发生改变,所以忽略碰撞,将计算得到的坐标进行排序后,就能知道每个球的最终位置。那么,R > 0是要怎么办呢?这种情况下上的处理方法基本相同,对于从下方开始的第i个球,在按照R = 0计算的结果上加上2Ri就好了。

 

//弹性碰撞
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 100 + 10;
const double g = 10.0;   //重力加速度

int N, H, R, T;
double y[maxn];   //球的最终位置

//求出T时刻球的位置
double calc(int T)
{
    if (T < 0)
        return H;
    double t = sqrt(2 * H / g);
    int k = (int)(T / t);
    if (k % 2 == 0){
        double d = T - k * t;
        return H - g * d * d / 2;
    }
    else{
        double d = k * t + t - T;
        return H - g * d * d / 2;
    }
}

void solve()
{
    for (int i = 0; i < N; i++){
        y[i] = calc(T - i);
    }
    sort(y, y + N);
    for (int i = 0; i < N; i++){
        printf("%.2lf%c", y[i] + 2 * R * i / 100.0, i + 1 == N ? '\n' : ' ');
    }
}

int main()
{
    int cas;
    scanf("%d", &cas);
    while (cas--){
        scanf("%d%d%d%d", &N, &H, &R, &T);
        solve();
    }
    return 0;
}


你可能感兴趣的:(POJ 3684 Physics Experiment 弹性碰撞)