3221. 北京记者跑得最快

10175102141

北京记者的速度真的是快的一匹

Fifnmar

只有做做水题才能维持得了生活的样子……

For each $x$, we have
$$\frac{1}{2}at^2+v_0t-x=0,$$
and it is obvious that
$$t=\frac{-v_0+\sqrt{v_0^2+2ax}}{a}.$$
We can easily notice that it can be transformed into
$$t=\sqrt{\frac{v_0^2}{a^2}+\frac{2x}{a}}-\frac{v_0}{a}.$$
To avoid repeated calculation, let
$$\alpha = \frac{v_0^2}{a^2},\;\;\;\beta = -\frac{v_0}{a},\;\;\;\theta = \frac{2}{a},$$
we have
$$t=\sqrt{\alpha+\beta x}+\theta.$$

Now, for each case, we only need two addition, one multiplication, and one square root calculation.

Hence is the code:

#include <cmath>
#include <cstdio>

int main() {
    int l, v0, a;
    scanf("%i%i%i", &l, &v0, &a);
    double c = -(double)v0 / a;
    double b = c * c;
    double d = 2.0 / a;
    for (int i = 1; i <= l; ++i)
        printf("%.9lf\n", std::sqrt(b + d * i) + c);
}
Chains.Z
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
    double l, v, a;
    cin >> l >> v >> a;
    for (double x = 1; x <= l; x++)
    {
        double delta = sqrt(v*v + 2*a*x);
        double time = (delta - v) / a;
        cout << setprecision(9) << time << endl;
    }
}
10152130146

这个题目出的啊,excited

你当前正在回复 博客/题目
存在问题!