您的位置:首页 > 其它

NPY and shot (三分求峰值)

2017-07-13 13:43 447 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: