Three points and three points to find the Extremum

Source: Internet
Author: User

Three points for extremum time limitation: 10000ms single point time limit: 1000ms memory limit: 256MB description

This time we will be a little simpler, the topic here:

In a Cartesian coordinate system, there is a parabolic y=ax^2+bx+c and a point P (x, y), which is the shortest distance d from the parabolic line to the point P.

Input

Line 1th: 5 integer a,b,c,x,y. The first three numbers constitute the parabolic parameters, and the last two numbers x, y represent P-point coordinates. -200≤a,b,c,x,y≤200

Output

Line 1th: A real number D, reserved 3 decimal places (rounded)

Sample input

2 8 2-2 6
Sample output
2.437
#include <iostream> #include <math.h> #include <float.h> #include <iomanip>using namespace std;    Double presult = 0.0;typedef struct funcparamter{double A;    Double b; Double C;}    funcparamter;typedef struct point{double x; Double y;} Point;double Calculator (funcparamter minefunc,point knownpoint,point foundpoint) {return sqrt ( Foundpoint.x-knownpoint.x) * (foundpoint.x-knownpoint.x) + (Minefunc.a*pow (foundpoint.x,2) +minefunc.b*foundpoint.x +MINEFUNC.C-KNOWNPOINT.Y) * (Minefunc.a*pow (foundpoint.x,2) +minefunc.b*foundpoint.x+minefunc.c-knownpoint.y));} Double Findy (double x,funcparamter minefunc) {return Minefunc.a*pow (x,2) +minefunc.b*x+minefunc.c;}    Double Findmin (double left,double right,funcparamter minefunc,point knownpoint) {point lm,rm;    lm.x = left+ (right-left)/3;    rm.x = left+2* (right-left)/3;    LM.Y = Findy (Lm.x,minefunc);    RM.Y = Findy (Rm.x,minefunc);   if ((Calculator (MINEFUNC,KNOWNPOINT,LM)-calculator (MINEFUNC,KNOWNPOINT,RM)) ==0) {     Double min = Calculator (minefunc,knownpoint,lm) <calculator (MINEFUNC,KNOWNPOINT,RM)?        Calculator (MINEFUNC,KNOWNPOINT,LM): Calculator (MINEFUNC,KNOWNPOINT,RM);        Cout<<setiosflags (ios::fixed) <<setprecision (3) <<min<<endl;    return min; } else if (Calculator (MINEFUNC,KNOWNPOINT,LM) <calculator (MINEFUNC,KNOWNPOINT,RM)) {Findmin (left,rm.x,minef    Unc,knownpoint);    } else {findmin (lm.x,right,minefunc,knownpoint);    }}int Main () {Funcparamter minefunc;    Point Knownpoint;    cout<<dbl_max<<endl;    cin>>minefunc.a>>minefunc.b>>minefunc.c>>knownpoint.x>>knownpoint.y;    Cout<<calculator (Minefunc,knownpoint,foundpoint) <<endl;    Findmin ( -1000,1000,minefunc,knownpoint); return 0;}

Tips

Three points and three points to find the Extremum

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.