HDU 2298 Toxophily

题意:人的坐标在原点,给出目标坐标(x,y) 和 原点的速度v,0 ≤ x, y, v ≤ 10000.问v和x的角度应该是多少,才能使得从思路原点发射的弓箭射中目标点。
思路:单峰的,可以三分,然而二元一次方程高中都学过,为什么不直接解出答案呢。
v* cosa* t = x; ==》t = x / v /cosa;
v* sina* t- 1/2* g * t * t = y;
消去t;x* tana - 1/2 * g x^2 (1 / v^2 / cosa^2) = y;
利用 sina^2 + cosa^2 = 1;把上面的式子变成
2* v^2 * tana - g * x^2 (1 + tana^2) = 2 v^2 *y;
这就变成了以tana为变量的二元一次方程。公式求一求就OK。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
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 a = g * x * x;
        double b = -2 * x * v * v;
        double c = g * x * x + 2 * v * v * y;
        double ok = b * b - 4 * a * c;
        if(ok < 0)
        {
            printf("-1\n");
            continue;
        }
        double x1 = atan((-b + sqrt(ok)) / (2 * a));
        double x2 = atan((-b - sqrt(ok)) / (2 * a));
        double ans = min(x1,x2);
        if(ans < 0) printf("-1\n");
        else printf("%6f\n",ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值