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,醉了,明明用的计量单位是弧度啊弧度。。。。**
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; }
相关文章推荐
- NPY and shot(三分)
- HDU 5144 NPY and shot(三分角度)
- HDU 5144 NPY and shot (公式+三分)
- hdu 5144 NPY and shot 物理+三分
- HDOJ 5144 NPY and shot(三分)
- HDU 5144 NPY and shot 三分(物理)
- HDU 5144 NPY and shot(物理运动学+三分查找)
- hdu 5144 NPY and shot(三分)
- BestCoder Round #22 03 NPY and shot(三分)
- [HDU5144]NPY and shot 解题报告
- HDU 5144 NPY and shot(三分法)
- HDU5144 NPY and shot
- 【CUGBACM15级BC第22场 C】hdu 5144 NPY and shot
- HDOJ 5144 NPY and shot
- hdu 5144 NPY and shot(物理+三分法)
- HDOJ 5144 NPY and shot 简单物理
- HDU5144 NPY and shot && BestCoder Round #22 1003
- hdu 5144 NPY and shot
- Webdriver MouseMove and Screen Shot
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E. Weakness and Poorness 三分