F. Two Points

There are two points (x1, y1) and (x2, y2) on the plane. They move with the velocities (vx1, vy1) and (vx2, vy2). Find the minimal distance between them ever in future.

Input

The first line contains four space-separated integers x1, y1, x2, y2 ( - 104 ≤ x1,  y1,  x2,  y2 ≤ 104) — the coordinates of the points.
The second line contains four space-separated integers vx1, vy1, vx2, vy2 ( - 104 ≤ vx1,  vy1,  vx2,  vy2 ≤ 104) — the velocities of the points.

Output

Output a real number d — the minimal distance between the points. Absolute or relative error of the answer should be less than 10 - 6.

Examples

Input

1 1 2 2
0 0 -1 0

Output

1.000000000000000

Input

1 1 2 2
0 0 1 0

Output

1.414213562373095


题意:

输入两个点坐标和速度向量
求这两个点能到的最近距离
输入

x1,y1,x2,y2vx1,vy1,vx2,vy2x_1 , y_1 , x2,y2 \\ v_{x_1},v_{y_1},v_{x_2},v_{y_2}


题解

求出距离表达式d=(x1x2+t×(vx1vx2))2+(y1y2+t×(vy1vy2))2d=\sqrt {(x_1-x_2+t\times(v_{x_1}-v_{x_2}))^2+(y_1-y_2+t\times(v_{y_1}-v_{y_2}))^2}
[0,105][0,10^5]三分ttdd的最小值即可

注意:在三分t的时候精度要高,答案要求为10610^{-6}但这是距离的精度,时间精度应该更大,这个题需要时间精度高于101010^{-10}

也可以不管精度,直接跑一百遍

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
double X1, Y1, x2, y2, vx1, vy1, vx2, vy2;
double pow2(double x) { return x * x; }
double check(double t)
{
return pow2(X1 - x2 + t * (vx1 - vx2)) + pow2(Y1 - y2 + t * (vy1 - vy2));
}
int main()
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &X1, &Y1, &x2, &y2, &vx1, &vy1, &vx2, &vy2);
double L, R;
L = 0;
R = 1e6;
int tot = 100;
while (tot--)
{
double mid1 = (L + L + R) / 3;
double mid2 = (R + R + L) / 3;
double ans1 = check(mid1);
double ans2 = check(mid2);
if (ans1 <= ans2)R = mid2;
else L = mid1;
}
double ans = sqrt(check(L));
printf("%.9f\n", ans);
}