NPY and shot (三分求峰值)

这篇博客探讨了NPY在PE测试中的铅球投掷问题。内容包括了NPY的身高、投掷速度以及如何计算在最佳角度下的最大投掷距离,其中重力加速度为9.8m/s²。博主分享了一个编程题目,要求计算在特定条件下,NPY能将铅球扔出的最远距离,并给出了样例输入和输出。博主提到在解决这个问题时,因为将角度上限错误地设为90(度),导致初赛时出现问题,实际上应该使用弧度作为单位。
摘要由CSDN通过智能技术生成

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/s29.8m/s2)
Input
The first line contains a integer T(T≤10000)T(T≤10000),which indicates the number of test cases.
The next T lines,each contains 2 integers H(0≤h≤10000m)H(0≤h≤10000m),which means the height of NPY,and v0(0≤v0≤10000m/s)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

Hint
If the height of NPY is 0,and he throws the shot at the 45° angle, he can throw farthest.

**题意:高度为H,初速度为0,g为9.8,问最大水平移动距离
简单的三分却wa了好久,原因是把二分上界设置成了90,醉了,明明用的计量单位是弧度啊弧度。。。。**


#include <string.h>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <iomanip>
using namespace std;
double h,v;
const double g = 9.8;
double f(double x)
{
    return v*cos(x)*(v*sin(x)/g+sqrt((2*h*g+v*sin(x)*v*sin(x))/(g*g)));
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lfd",&h,&v);
        double l=0,r=asin(1.0);//被这里坑了好久。。。它是弧度啊啊啊啊啊啊啊啊写成90不wa才怪
        for(int i=0;i<100;i++)
        {
           double midst,midend;
           midst=(l+r)/2;
           midend=(midst+r)/2;
           if(f(midst)-f(midend)<1e-10)
               l=midst;
           else
               r=midend;
        }
        cout<<fixed<<setprecision(2)<<f(l)<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值