hdu 5144 NPY and shot
http://acm.hdu.edu.cn/showproblem.php?pid=5144
题意:给你初始的高度和速度,然后让你求出水平的最远距离。
思路:三分枚举角度,然后根据公式求出水平距离。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 using namespace std; 6 const double pi=acos(-1.0); 7 const double eps=1e-6; 8 const double g=9.8; 9 10 int t; 11 double h,v; 12 double ok(double x) 13 { 14 double xx=((double)(x/180))*pi; 15 double t1=v*sin(xx)/g; 16 double y=v*t1*sin(xx)-0.5*g*t1*t1; 17 double yy=y+h; 18 double t2=sqrt(yy*2/g); 19 double s=v*cos(xx)*(t1+t2); 20 return s; 21 } 22 23 int main() 24 { 25 scanf("%d",&t); 26 while(t--) 27 { 28 scanf("%lf%lf",&h,&v); 29 double l=0,r=90; 30 double c; 31 while(r-l>eps) 32 { 33 double mid1=(r+l)/2; 34 double mid2=(l+mid1)/2; 35 if(ok(mid1)>=ok(mid2)) 36 { 37 c=mid1; 38 l=mid2; 39 } 40 else 41 r=mid1; 42 } 43 printf("%.2lf\n",ok(c)); 44 } 45 return 0; 46 }