HDU 2298 Toxophily(公式推导)

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

  1. T ≤ 100.
  2. 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θt21gt2
代入
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+x2y2 sin2θ1+x2y2 xy=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+x2y2 gv2x+xy

其中 c o s φ = 1 1 + y 2 x 2 cos\varphi=\frac{1}{\sqrt{1+\frac{y^{2}}{x^{2}}}} cosφ=1+x2y2 1

再用反三角函数可以求出$\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+x2y2 gv2x+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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值