Answer series: Xi'an Network Competition 1011
The shortest distance from the source to the source is obtained.
Ideas:
For an elliptical standard equation x ^ 2/A ^ 2 + y ^ 2/B ^ 2 + Z ^ 2/C ^ 2 = 1, the shortest distance to the origin is Min (A, B, C)
So we need to turn the original equation into a standard type.
At this time, the line generation will come in handy. It is noted that the original equation is a quadratic form.
Standard Type 1/(K1) * x ^ 2 + 1/(K2) * y ^ 2 + 1/(K3) * Z ^ 2 = 1 min (K1, K2, k3) is the answer
Here, 1/K1, 1/K2, 1/K3 are the feature values of the quadratic matrix.
How can we find the feature value?
We write a quadratic matrix.
| A f/2 E/2 |
T = | f/2 B D/2 |
| E/2 D/2 c | by the determinant | λ e-T | = 0, we can get a one-dimensional cubic equation about λ, so that k = 1/λ,
Record it as a * k ^ 3 + B * k ^ 2 + C * k + D = 0 (note that A, B, C, and D here are all about a in the original process, polynomial of B, C, D)
To solve this one-dimensional cubic equation, you can use the root formula: shengjin formula (I will not use other methods)
We can solve the problem in four cases ..
Code:
#include <stdio.h>#include<algorithm>#include<math.h>using namespace std;#define MAXN 10000const double p=sqrt(3.0);const double inf=0.0000001;double min(double a,double b,double c){ return min(a,min(b,c));}int main(){ double aa,bb,cc,dd,ee,ff; double A,B,C,a,b,c,d; while(scanf("%lf%lf%lf%lf%lf%lf",&aa,&bb,&cc,&dd,&ee,&ff)!=EOF) { double ans; a=4*aa*bb*cc+dd*ee*ff-bb*ee*ee-aa*dd*dd-ff*ff*cc; b=4*aa*bb+4*bb*cc+4*aa*cc-ee*ee-ff*ff-dd*dd; c=4*aa+4*bb+4*cc; d=4.0; A=b*b-3*a*c; B=b*c-9*a*d; C=c*c-3*b*d; double q=B*B-4*A*C; if(fabs(A-B)<inf&&fabs(A)<inf) { printf("%.8lf\n",sqrt(fabs(-c/b))); continue; } if(fabs(B*B-4*A*C)<inf) { double k=B/A; ans=min(fabs(-b/a+k),fabs(-k/2)); printf("%.8f\n",sqrt(ans)); continue; } if(q>0) { double x=A*b+3*a*((-B+sqrt(q))/2); double y=A*b+3*a*((-B-sqrt(q))/2); double t1= x>0?pow(x,1.0/3):-(pow(fabs(x),1.0/3)); double t2= y>0?pow(y,1.0/3):-(pow(fabs(y),1.0/3)); ans=(-b-t1-t2)/(3*a); printf("%.8f\n",sqrt(fabs(ans))); continue; } double t=acos((2*A*b-3*a*B)/(2*sqrt(A*A*A)))/3; ans=min(fabs((-b-2*sqrt(A)*cos(t))/(3*a)),fabs(((-b)+sqrt(A)*(cos(t)+p*sin(t)))/(3*a)),fabs(((-b)+sqrt(A)*(cos(t)-p*sin(t)))/(3*a))); printf("%.8f\n",sqrt(ans)); } return 0;}
Hdu5017: Xi'an Network Competition 1011