NPY and shot HDU - 5144(物理+三分)

2 篇文章 0 订阅

题目来源: NPY and shot

Problem Description

NPY is going to have a PE test.One of the test subjects is throwing the shot.The height of NPY is H meters.He can throw the shot at the speed of v0 m/s and at the height of exactly H meters.He wonders if he throws the shot at the best angle,how far can he throw ?(The acceleration of gravity, g, is 9.8m/s2)

Input

The first line contains a integer T(T≤10000),which indicates the number of test cases.
The next T lines,each contains 2 integers H(0≤h≤10000m),which means the height of NPY,and v0(0≤v0≤10000m/s), which means the initial velocity.

Output

For each query,print a real number X that was rounded to 2 digits after decimal point in a separate line.X indicates the farthest distance he can throw.

Sample Input

2
0 1
1 2

Sample Output

0.10
0.99

题意

一个人站在高度为h的的地方以初速度v0向前斜抛,求水平位移的最大值

思路

利用高中物理可求得水平位移x=sqrt(v02-vy2)(vy+sqrt(vy^2+2gh))/g, vy是竖直方向上的初速度。

vy的范围是[0, v0],问题转化为在区间[0, v0]上求方程的最大值,三分。

输出保留两位小数

代码

#include<bits/stdc++.h>
using namespace std;
int h, v;
double f(double x)
{
    double k1 = sqrt(v*v - x * x);
    double k2 = x + sqrt(x*x + 2 * 9.8*h);
    return k1 * k2 / 9.8;
}
double solve()
{
    double l = 0, r = v, mid1, mid2;
    for (int i = 1; i <= 1000; ++i)
    {
        mid1 = (l + r) / 2;
        mid2 = (mid1 + r) / 2;
        if (f(mid1) < f(mid2))
            l = mid1;
        else
            r = mid2;
    }
    return f(l);
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> h >> v;
        cout << setiosflags(ios::fixed) << setprecision(2) << solve() << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值