Topic:
#1142: three points • Three points for extreme 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.
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
Problem Solving Ideas:
This problem, we know that we should ask for d = min (sqrt (x-x) ^2+ (y-y) ^2), then we know our objective function, we should put this function to simplify, after simplification, we know that this function is a four-time function, It is simply impossible to achieve the most common method of deriving extreme values. To further observe the topic, we can find that the length of D is exactly the convex function, depending on the X value brought in.
The shortest distance we ask for D is exactly the extremum of this convex function.
Code:
1# include <cstdio>2# include <iostream>3# include <cmath>4 using namespacestd;5 Doublea,b,c,x,y;6 DoublePossibleDoublex)7 {8 Doubley = a*x*x+b*x+C;9 Doubleres = Hypot (x-x,y-y);Ten returnRes; One } A intMainvoid) - { -Cin>>a>>b>>c>>x>>Y; the DoubleL =-233.0; - DoubleR =233.0; - while(ABS (R-L) > 1e-8 ) - { + DoubleM1 = L + (r-l)/3; - DoubleM2 = r (r-l)/3; + if(Possible (M1) <Possible (m2)) A { atR =m2; - } - Else - { -L =M1; - } in } -printf"%.3lf\n", (Possible (L) + (Possible (r)))/2); to + - return 0; the}
Three points • Three points to find the extreme value algorithm explanation and topic