Description two vertices A and B are uniformly moving in a straight line. The coordinates of A and B at T = 0, and the velocity of A and B are given. The minimum value of the distance between the two points is calculated when T is greater than or equal to 0. The first line of input contains an integer T (1 ≤ T ≤ 200), indicating a total of T groups of test data. For each group of test data, the first row contains four integers: XA, ya, VAX, vay (-103 ≤ XA, ya, VAX, vay ≤ 103 ), it indicates that the coordinate of A at T = 0 is (XA, ya). The component of A's speed on the X axis is vax, and the component on the Y axis is vay. The second row contains four integers: XB, Yb, vbx, and vby (-103 ≤ XB, Yb, vbx, and vby ≤ 103). The attributes of B are given in the same way. For each group of test data, output T is equal to or greater than 0, and the minimum distance between the two points is retained with 8 decimal places. Sample Input
60 0 0 00 1 0 10 0 -1 10 0 1 -10 1 1 02 0 0 10 1 1 02 0 1 00 0 -1 11 1 1 -1997 997 -1000 -1000-1000 -1000 1000 1000
Sample output
1.000000000.000000000.707106782.236067981.414213560.00000000
Hint
Source
The Eighth Program Design Competition for Central South University Students
/Obtain the coordinates of A and B at the T moment, and then use the distance formula to find the distance between D = A and B. It is a binary equation about T and A is obtained based on known conditions, b, c, Judgment, the simplest way to direct
1. Obtain the vertex coordinates, that is,-B/2/. If the number is greater than or equal to 0, calculate the vertex function value.
2. Calculate the function value of the point 0.
Take the values 1 and 2 for Min. Note that if a in 1 is equal to 0, you do not need to consider 1. Parabolic vertex (-2 * a/B, SQRT (B * B-4 * a * C)/4 * ;)
#include<cstdio>#include<cmath>using namespace std;#define maxn 0xfffffffint main(){ int t,xa,ya,vax,vay,xb,yb,vbx,vby,i,j; double a,b,c,s,ans; scanf("%d",&t); while(t--) { s=0; ans=maxn; scanf("%d%d%d%d",&xa,&ya,&vax,&vay); scanf("%d%d%d%d",&xb,&yb,&vbx,&vby); a=(vax-vbx)*(vax-vbx)+(vay-vby)*(vay-vby); b=2*((xa-xb)*(vax-vbx)+(ya-yb)*(vay-vby)); c=(xa-xb)*(xa-xb)+(ya-yb)*(ya-yb); //printf("%lf %lf %lf\n",a,b,c); if(a==0) printf("%.8lf\n",sqrt(c)); else { s=-b/a/2; //printf("%lf\n",s); if(s>0) ans=(4*a*c-b*b)/4/a; // printf("%lf\n",ans); ans=sqrt(ans); c=sqrt(c); printf("%.8lf\n",ans>c?c:ans); } } return 0;}
CSU-1407: Shortest Distance