CF BUDDY
← Problems·

1886B · Fear of the Dark

1200 · binary search, geometry, math

Problem: Monocarp tries to get home from work. He is currently at the point O=(0,0)O = (0, 0) of a two-dimensional plane; his house is at the point P=(Px,Py)P = (P_x, P_y).

Unfortunately, it is late in the evening, so it is very dark. Monocarp is afraid of the darkness. He would like to go home along a path illuminated by something.

Thankfully, there are two lanterns, located in the points A=(Ax,Ay)A = (A_x, A_y) and B=(Bx,By)B = (B_x, B_y). You can choose any non-negative number ww and set the power of both lanterns to ww. If a lantern's power is set to ww, it illuminates a circle of radius ww centered at the lantern location (including the borders of the circle).

You have to choose the minimum non-negative value ww for the power of the lanterns in such a way that there is a path from the point OO to the point PP which is completely illuminated. You may assume that the lanterns don't interfere with Monocarp's movement.

The picture for the first two test cases

Input Format: The first line of the input contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases.

Each test case consists of three lines:

  • the first line contains two integers PxP_x and PyP_y (103Px,Py103-10^3 \le P_x, P_y \le 10^3) — the location of Monocarp's house;
  • the second line contains two integers AxA_x and AyA_y (103Ax,Ay103-10^3 \le A_x, A_y \le 10^3) — the location of the first lantern;
  • the third line contains two integers BxB_x and ByB_y (103Bx,By103-10^3 \le B_x, B_y \le 10^3) — the location of the second lantern.

Additional constraint on the input:

  • in each test case, the points OO, PP, AA and BB are different from each other.

Output Format: For each test case, print the answer on a separate line — one real number equal to the minimum value of ww such that there is a completely illuminated path from the point OO to the point PP.

Your answer will be considered correct if its absolute or relative error does not exceed 10610^{-6} — formally, if your answer is aa, and the jury's answer is bb, your answer will be accepted if abmax(1,b)106\dfrac{|a - b|}{\max(1, b)} \le 10^{-6}.

Sample Cases

Case 1

Input

2
3 3
1 0
-1 6
3 3
-1 -1
4 3

Output

3.6055512755
3.2015621187

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback