Toxophily
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2314 Accepted Submission(s): 1279
Problem Description
The recreation center of WHU ACM Team has indoor billiards, Ping Pang, chess and bridge, toxophily, deluxe ballrooms KTV rooms, fishing, climbing, and so on.
We all like toxophily.
Bob is hooked on toxophily recently. Assume that Bob is at point (0,0) and he wants to shoot the fruits on a nearby tree. He can adjust the angle to fix the trajectory. Unfortunately, he always fails at that. Can you help him?
Now given the object’s coordinates, please calculate the angle between the arrow and x-axis at Bob’s point. Assume that g=9.8N/m.
Input
The input consists of several test cases. The first line of input consists of an integer T, indicating the number of test cases. Each test case is on a separated line, and it consists three floating point numbers: x, y, v. x and y indicate the coordinate of the fruit. v is the arrow’s exit speed.
Technical Specification
- T ≤ 100.
- 0 ≤ x, y, v ≤ 10000.
Output
For each test case, output the smallest answer rounded to six fractional digits on a separated line.
Output “-1”, if there’s no possible answer.
Please use radian as unit.
Sample Input
3
0.222018 23.901887 121.909183
39.096669 110.210922 20.270030
138.355025 2028.716904 25.079551
Sample Output
1.561582
-1
-1
题意:一个二维平面,你在(0,0)点,在(x,y)点有一个水果,你要用箭把他射下来,给你(x,y)和箭的初速度v,求发射的最小角度(与x轴所成的角度),g=9.8。
思路:高中物理题,分解成x方向和y方向的那么有如下式子
$ t=\frac{x}{vcos\theta }$
y
=
v
s
i
n
θ
t
−
1
2
g
t
2
y=vsin\theta t-\frac{1}{2}gt^{2}
y=vsinθt−21gt2
代入
y
=
x
t
a
n
θ
−
1
2
g
x
2
v
2
c
o
s
2
θ
y=xtan\theta -\frac{1}{2}g\frac{x^{2}}{v^{2}cos^{2}\theta}
y=xtanθ−21gv2cos2θx2
两边同时乘以
c
o
s
2
θ
x
\frac{cos^{2}\theta}{x}
xcos2θ得
$sin\theta cos\theta -\frac{1}{2}g\frac{x}{v{2}}=\frac{y}{x}cos{2}\theta $
移项用二倍角公式得
s
i
n
2
θ
−
y
x
c
o
s
2
θ
=
g
x
v
2
+
y
x
sin2\theta -\frac{y}{x}cos2\theta =g\frac{x}{v^{2}}+\frac{y}{x}
sin2θ−xycos2θ=gv2x+xy
利用辅助角公式提出
a
2
+
b
2
\sqrt{a^{2}+b^{2}}
a2+b2也就是
1
+
y
2
x
2
\sqrt{1+\frac{y^{2}}{x^{2}}}
1+x2y2得
1
+
y
2
x
2
(
s
i
n
2
θ
1
+
y
2
x
2
−
y
x
1
+
y
2
x
2
)
=
g
x
v
2
+
y
x
\sqrt{1+\frac{y^{2}}{x^{2}}}\left ( \frac{sin2\theta }{\sqrt{1+\frac{y^{2}}{x^{2}}}}-\frac{\frac{y}{x}}{\sqrt{1+\frac{y^{2}}{x^{2}}}} \right )=g\frac{x}{v^{2}}+\frac{y}{x}
1+x2y2⎝⎛1+x2y2sin2θ−1+x2y2xy⎠⎞=gv2x+xy
两边除于 1 + y 2 x 2 \sqrt{1+\frac{y^{2}}{x^{2}}} 1+x2y2再用两角和差公式得
s i n ( 2 θ − φ ) = g x v 2 + y x 1 + y 2 x 2 sin\left ( 2\theta-\varphi \right )=\frac{g\frac{x}{v^{2}}+\frac{y}{x}}{\sqrt{1+\frac{y^{2}}{x^{2}}}} sin(2θ−φ)=1+x2y2gv2x+xy
其中 c o s φ = 1 1 + y 2 x 2 cos\varphi=\frac{1}{\sqrt{1+\frac{y^{2}}{x^{2}}}} cosφ=1+x2y21
再用反三角函数可以求出$\varphi $和$2\theta -\varphi 那 么 那么 那么\theta$也就求出了
明显的当 g x v 2 + y x 1 + y 2 x 2 \frac{g\frac{x}{v^{2}}+\frac{y}{x}}{\sqrt{1+\frac{y^{2}}{x^{2}}}} 1+x2y2gv2x+xy大于1时无解输出-1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
const double g=9.8;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
double x,y,v;
scanf("%lf%lf%lf",&x,&y,&v);
double theta=(g*x/(v*v)+y/x)/sqrt(1+y*y/x/x);
if(theta>1)
printf("-1\n");
else
{
double phi=1/sqrt(1+y*y/x/x);
phi=acos(phi);
theta=asin(theta);
printf("%lf\n",(theta+phi)/2);
}
}
return 0;
}