题解:P16466 [GKS 2013 Practice] Captain Hammer

· · 题解

P16466 [GKS 2013 Practice] Captain Hammer 题解

斜抛运动水平射程公式:

D = \frac{V^2 \sin2\theta}{g}

对公式进行移项变形可得出:

\sin2\theta = \frac{D \cdot g}{V^2}

令

x = \frac{D \cdot g}{V^2}

由于正弦函数值域为 [-1,1],若 x>1,则取 x=1,保证有解。

AC code :


# include <bits/stdc++.h>//万能头文件 
using namespace std;
int t;
double v,d;
int main () {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> t;
    cout << fixed << setprecision(7);
    for (int i = 1;i <= t;i++) {
        cin >> v >> d;
        double x = d * 9.8 / (v * v);
        if(x > 1.0) x = 1.0;
        cout << "Case #" << int(i) << ": " << 0.5 * asin(x) * 180.0 / acos(-1.0) << endl;//直接用公式写 
    }
    return 0;
}