北京记者的速度真的是快的一匹
这个题目出的啊,excited
只有做做水题才能维持得了生活的样子……
For each x, we have 12at2+v0t−x=0, and it is obvious that t=−v0+v02+2axa. We can easily notice that it can be transformed into t=v02a2+2xa−v0a. To avoid repeated calculation, let α=v02a2,β=−v0a,θ=2a, we have t=α+βx+θ.
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); }
#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; } }
北京记者的速度真的是快的一匹
这个题目出的啊,excited
只有做做水题才能维持得了生活的样子……
For each , we have
and it is obvious that
We can easily notice that it can be transformed into
To avoid repeated calculation, let
we have
Now, for each case, we only need two addition, one multiplication, and one square root calculation.
Hence is the code: