Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 808 Accepted Submission(s): 342
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.
#include<stdio.h> #include<iostream> #include<string.h> #include <stdlib.h> #include<math.h> #include<algorithm> using namespace std; double v,h,t1,t2; const double g = 9.8; const double pi = 3.1415926; const double eps = 1e-8; double Calc(double t) { t1 = sin(t)*v/g; t2 = sqrt((h+v*sin(t)*t1-0.5*g*t1*t1)*2/g); return (t1+t2)*v*cos(t); } double solve(double MIN,double MAX) { double Left, Right; double mid, midmid; double mid_value, midmid_value; Left = MIN; Right = MAX; while (Left +eps < Right) { mid = (Left + Right) / 2; midmid = (mid + Right) / 2; mid_value = Calc(mid); midmid_value = Calc(midmid); ///求最大值改成>= 最小值改成<= if (mid_value >= midmid_value) Right = midmid; else Left = mid; } return Left; } int main() { int tcase; scanf("%d",&tcase); while(tcase--) { scanf("%lf%lf",&h,&v); double angle = solve(0,pi/2); ///注意是[0,pi/2],不是[0,90] printf("%.2lf\n",Calc(angle)); } return 0; }