At that time to do this problem has always wanted to quit the physical formula, but later pushed to the derivative that part, due to the mathematical bad, did not launch the most value of theta, then direct violence, obviously timed out, forget the application of the three-part method, the problem is a typical three-point to find the most value, is a single peak curve, the
1#include <stdio.h>2#include <math.h>3 #definePI 3.14159264 intV, H;5 DoubleFDoubleI//tear down the physical formula6 {7 returnv*v*1.0*sin (2*i)/9.8+ (sqrt (v*v*1.0*sin (i) *sin (i) +2.0*9.8*H)-v*sin (i))/9.8* v*cos (i);8 }9 intMain ()Ten { One intT; Ascanf"%d", &T); - while(t--) - { thescanf"%d%d", &h, &v); - DoubleAns =0.0; - DoubleL =0.0, R = pi/2; - DoubleMIDL, MIDR; + while(R-l >= 1e-6)//three points to find the most value - { +Midl= (2*L+R)/3;//is derived from MIDL = (r-l)/3 + L Simplification AMidr= (L +2*R)/3;//is by Midr = (r-l) * 2/3 + L simplified at if(f (MIDL) >f (MIDR))//the picture looks better with this relationship -R=Midr; - Else -L=MIDL; - } -printf"%.2lf\n", F ((R+L)/2)); in } - to return 0; +}
HDU 5144 NPY and shot (three-part method)