javaee论坛

普通会员

225648

帖子

335

回复

349

积分

楼主
发表于 2017-07-17 22:31:33 | 查看: 510 | 回复: 1
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;}

超级管理员

98

帖子

391

回复

10864

积分
沙发
发表于 2017-07-17 22:32:45

您需要登录后才可以回帖 登录 | 立即注册

触屏版| 电脑版

技术支持 历史网 V2.0 © 2016-2017