#1142: three points • Three points for extremum (three-point extremum)

Source: Internet
Author: User


#1142: three points • Three points for extremum
Time limit: 10000ms
Single point time limit: 1000ms
Memory Limit: 256MB

Describe

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



[Week40_1.png]
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.

Tip: Three-point method
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


Three-point extremum #include<cstdio> #include <algorithm> #include <cmath>//#include <bits/stdc++.h>using    namespace Std;template<class t>inline T Read (t&x) {char C;    while ((C=getchar ()) <=32) if (c==eof) return 0;    BOOL Ok=false;    if (c== '-') Ok=true,c=getchar ();    for (x=0; c>32; C=getchar ()) x=x*10+c-' 0 ';    if (OK) x=-x; return 1;} Template<class t> inline T read_ (t&x,t&y) {return read (x) &&read (y);} Template<class t> inline T read__ (t&x,t&y,t&z) {return read (x) &&read (y) &&read (z);}    Template<class t> inline void Write (T x) {if (x<0) Putchar ('-'), x=-x;    if (x<10) putchar (x+ ' 0 '); else write (X/10), Putchar (x%10+ ' 0 ');}    Template<class t>inline void Writeln (T x) {write (x); Putchar (' \ n ');} -------ZCC IO template------const int MAXN=1000011;CONST double inf=999999999; #define Lson (rt<<1), L,m#define Rson (rt<<1|1), M+1,r#define M ((l+r) >>1) #define for (i,t,n) foR (int i= (t);i< (n); i++) typedef long Long Ll;typedef double db;typedef pair<int,int> P; #define BUG printf ("---\ n" ); #define MOD 10007double px,py;double a,b,c;double D (double x) {return sqrt (x-px) * (X-PX) + (a*x*x+b*x+c-py) * (a*x*x+b*x +c-py));}    DB TS (double left,double right) {db Lm,rm,dis;    DB y1=0,y2=0;        while (left<=right) {dis= (Right-left)/3.0;        Lm=left+dis;        Rm=lm+dis;        Y1=d (LM), Y2=d (RM);        printf ("%lf%lf\n", left,right);        GetChar ();        if (y1==y2) return y1;        else if (y1<y2) {right=rm;        } else {left=lm; }} return min (y1,y2);}    0.421int Main () {//#ifndef Online_judge//Freopen ("In.txt", "R", stdin);    #endif//Online_judge int n,m,i,j,t; while (~SCANF ("%lf%lf%lf%lf%lf", &a,&b,&c,&px,&py)) {if (d (PX) ==py) printf ("%0.00\n        ");    else printf ("%.3lf\n", TS (-200,200)); } return 0;} 






#1142: three points • Three points for extremum (three-point 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.