Title Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1407
Descriptiontwo points
A,
Bare doing uniform motion. Give the
T= 0 Moments
A,
Bthe coordinates, and
A,
Bthe speed, calculation
T≥0 O'Clock the minimum value of the distance between two points. Inputthe first line of input contains an integer
T(1≤
T≤ $), indicating that there are altogether
TGroup test Data. for each set of test data, the first row consists of 4 integers
x
A,
y
A,
v
Ax,
v
Ay( -103≤
x
A,
y
A,
v
Ax,
v
Ay≤Ten3), indicating
T= 0 Moments
Athe coordinates are (
x
A,
y
A),
Athe speed in
xthe component in the axis direction is
v
Ax, in
ythe component on the axis is
v
Ay. The second line consists of four integers
x
B,
y
B,
v
Bx,
v
by( -103≤
x
B,
y
B,
v
Bx,
v
by≤Ten3), in the same way given the
Bof the various properties. Outputfor each set of test data, the output
T ≥0 O'Clock the minimum value of the distance between two points, preserving 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 annual college student Program Design Competition
The code is as follows:
#include <cstdio> #include <cmath> #include <cstring>int main () {int t; Double xa, ya, vax, Vay; Double XB, YB, VBX, Vby; scanf ("%d", &t); while (t--) {scanf ("%lf%lf%lf%lf", &xa,&ya,&vax,&vay); scanf ("%lf%lf%lf%lf", &xb,&yb,&vbx,&vby); dis^2 = A*t^2+b*t+c Double A = ((VAX-VBX) * (VAX-VBX) + (vay-vby) * (Vay-vby)); A must be >=0 double b = xa* (VAX-VBX) +xb* (Vbx-vax) +ya* (Vay-vby) +yb* (Vby-vay)); Double c = xa* (XA-2*XB) +ya* (YA-2*YB) +yb*yb+xb*xb; Double dis1 = 0, Dis2 = 0, dis3 = 0; Double xx =-(2*a)/b;//vertex coordinates double yy = sqrt ((4*a*c-b*b)/(4*a)); Double d =-b/(2*a);//Solution: derivative: 2*a*x+b = 0; if (a = = 0) {dis1 = sqrt (c); printf ("%.8lf\n", dis1); } else if (a > 0) {if (d >= 0) {dis2 = yy; } else {dis2 = sqrt (c); } printf ("%.8lf\n", Dis2); }//printf ("dis1:%.8lf\n", dis1);//printf ("dis2:%.8lf\n", Dis2); } return 0;}
CSU 1407: Shortest distance (math AH)