碰撞问题。
弹性碰撞交换速度和方向,可以当成两个质点相互交错而过,不影响最后的结果,因为只需要排序就可以知道,最低的一定是最先放下的,以此类推。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<map>
#define up(i,a,b) for(int i=a;i<b;i++)
#define dw(i,a,b) for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
const double esp = 1e-6;
const double pi = acos(-1.0);
const long long INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int, int> pir;
const double g = 10.0;
int c, n,h, r, t;
double solve( int t1)
{
if (t1 < 0)return h;
double tempt = sqrt(2 * h / g);
//cout << tempt << endl;
double ans;
int k = t1 / tempt;
//cout << k << endl;
if (k & 1)
{
ans = (double)h - ((k+1)*tempt-t1)*((k+1)*tempt-t1)*g / 2;
}
else
{
ans = (double)h - (t1-k*tempt)*(t1-k*tempt )*g / 2;
}
return ans;
}
int main()
{
cin >> c;
while (c--)
{
double ans[1005];
cin >> n >> h >> r >> t;
//h *= 100;
up(i, 0, n)
{
ans[i] = solve(t - i);
}
sort(ans, ans + n);
up(i, 0, n)
{
printf("%.2f%c", ans[i] + 2.0*r*i / 100.0,(i+1)==n?'\n':' ');
}
}
return 0;
}