您的位置:首页 > 其它

HDU 5144 NPY and shot(物理运动学+三分查找)

2017-03-15 22:43 393 查看

NPY and shot

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1035 Accepted Submission(s): 428

[align=left] [/align]

[align=left]Problem Description[/align]
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)

[align=left]Input[/align]
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.

[align=left]Output[/align]
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.

[align=left]Sample Input[/align]

2

0 1

1 2

[align=left]Sample Output[/align]

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.

[align=left]Source[/align]
BestCoder Round #22
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5144
分析:做三分做上瘾了,再来一道,物理数学得学好啊,不然有些题就算算法知道你也写不来啊,都是思维题,典型的质点运动学+三分查找!
下面给出AC代码:

#include <bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
const double g=9.8;
double v,h;
const double eps=1e-8;
double ans(double a)
{
double a1=v*v*sin(a)*sin(a);
double a2=2*g*h;
a1=a1+a2;
a1=sqrt(a1);
a1=a1/g;
a1=a1+v*sin(a)/g;
a1=a1*v*cos(a);
return a1;
}
int main()
{
int T;
while(scanf("%d",&T)!=EOF)
{
while(T--)
{
scanf("%lf%lf",&h,&v);
double l=0;
double r=pi/2;
double midx,midy;
while (r-l>eps)
{
midx=(l+l+r)/3;
midy=(l+r+r)/3;
if(ans(midx)>ans(midy))
r=midy;
else l=midx;
}
printf("%.2f\n",ans(l));
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: