Physics Experiment
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2735 Accepted: 976 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).
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 N, H, R, T.
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
Source
POJ Founder Monthly Contest – 2008.08.31, Simon
将完全弹性碰撞看作是直接交换两个小球的位置进行穿透处理。
就可以解决了。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
const double g = 10.0;
const int maxn = 105;
const double eps = 1E-8;
double y[maxn];
int N;
int H, R;
int T;
double calc(int x)
{
if (x < 0)
return H;
double t = sqrt(2*H / g);
int k = (int)(x/t);
if (k % 2 == 0)
{
double d = x - k*t;;
return H - g*d*d / 2;
}
else
{
double d = k*t + t - x;
return H - g*d*d / 2;
}
}
void solve()
{
memset(y, 0, sizeof(y));
for (int i = 0; i < N; i++)
{
y[i] = calc(T - i);
}
sort(y, y + N);
for (int i = 0; i < N; i++)
{
//cout << y[i] + 2 * R*(i - 1) / 100.0 << endl;
printf("%.2f%c", y[i] +2*R*i/100.0, i == N - 1 ? '\n' : ' ');
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
//memset(y, 0, sizeof(y));
cin >> N >> H >> R >> T;
solve();
}
return 0;
}