HDU 5144 NPY and shot (three-part method)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.