UVa 1333 - Model Rocket Height

链接

传送门

题意

有三个高度相同的观测点共线,两两之间距离相等,给出观测点间的距离\(d\),三个观测点的高度\(h\),观测时的仰角\(\alpha\)\(\beta\)\(\gamma\),求火箭的高度。

思路

设火箭高于观测点高度为\(x\),火箭与三个观测点在平面上的投影分别为\(A\)\(B\)\(C\)\(D\)

易得

\[AB=\frac{x}{\tan{\alpha}},\space AD=\frac{x}{\tan{\beta}},\space AC=\frac{x}{\tan{\gamma}}, \space BC=2d\]

由中线定理得

\[AD=\frac{1}{2}\sqrt{2AB^2+2AC^2-BC^2}\]

带入得

\[4\left(\frac{x}{\tan{\beta}}\right)^2=2\left(\frac{x}{\tan{\alpha}}\right)^2+2\left(\frac{x}{\tan{\gamma}}\right)^2-4d^2\]

\[x^2\cdot\left(\frac{1}{\tan^2\alpha}+\frac{1}{\tan^2\gamma}-\frac{2}{\tan^2\beta}\right)=2d^2\]

解得

\[x=d\cdot\sqrt{\frac{2}{y}},\space y=\left(\frac{1}{\tan^2\alpha}+\frac{1}{\tan^2\gamma}-\frac{2}{\tan^2\beta}\right)\]

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const double PI = acos(-1);

int main() {
double a, b, c, d, h;
scanf("%lf%lf", &d, &h);
while(~scanf("%lf%lf%lf", &a, &b, &c) && (a > 0 || b > 0 || c > 0)) {
a = tan(a * PI / 180), b = tan(b * PI / 180), c = tan(c * PI / 180);
printf("%.0f\n", d * sqrt(2 / (1 / a / a + 1 / c / c - 2 / b / b)) + h);
}
return 0;
}