题目链接
思路
$$ 弹性碰撞问题\\\\ 1.每个球都相当于从高度为h处下落,原因是第i(i 从 0 开始)个球的高度为h+i × 2 × r,\\\\ 下边有i个球,因为下边每有一个球,都相当于下落的距离减少2×r.\\\\ 2.先当r为0求完后再把高度加回去 $$
时间复杂度
$$ O(Nlog(N)) $$
代码
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
vector<double> vec;
int g = 10;
double gao(double h, int t) {
if (t <= 0) {
return h;
}
double t1 = sqrt(2.0 * h / g);
int k = t / t1;
if (k & 1) {
double d = k * t1 + t1 - t;
return h - g * d * d / 2;
} else {
double d = t - k * t1;
return h - g * d * d / 2;
}
}
int main() {
int T;
scanf("%d", &T);// don't forget &
while (T--) {
int n, h, r, t;
scanf("%d%d%d%d", &n, &h, &r, &t);// don't forget &
vec.resize(n);
for (int i = 0; i < n; i++) {
vec[i] = gao(h, t - i);
}
sort(vec.begin(), vec.end());
for (int i = 0; i < n; i++) {
printf("%.2f%c", vec[i] + 2.0 * i * r / 100, " \n"[i == n - 1]);
}
}
return 0;
}