poj3684 Physics Experiment

//挑战的分析已经很详细了,P157-158,我也就不再赘言
//注意单位,输入单位是厘米,输出的要是米
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
const double g = 10.0;
const int maxn = 105;
double y[maxn];

int N, H, R, T;

double calc(int T)
{
	// 求出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.0;
	}
	else
	{
		double d = k * t + t - T;
		return H - g * d * d / 2.0;
	}
}

void solve()
{
	for (int i = 0; i < N; i++)
	{
		y[i] = calc(T - i);
	}
	sort(y, y + N);
	for (int i = 0; i < N - 1; i++)
	cout << fixed << setprecision(2) << y[i] + 2 * R * i / 100. << " ";
	cout << fixed << setprecision(2) << y[N - 1] + 2 * R * (N - 1) / 100. << endl;
}

int main()
{
	int k;
	cin >> k;
	while (k--)
	{
		cin >> N >> H >> R >> T;
		solve();
	}

	return 0;
}

原文地址:https://www.cnblogs.com/mofushaohua/p/7789459.html