This page is still under construction.

Parts of this page are still being built. What you see may change.

Sewerage Planning

Time limit1sMemory limit128 MB

Summary
Find the line through the rectangle that maximizes the minimum distance to the given points.
Level

Hard8 of 10

Topics
Geometry, Binary search
Solved
No attempts yet

Problem

ICPC City is a fast-growing city. Its population has risen so quickly that several public facilities now need to be improved, extended, or renovated. One of them is the sewerage system: a recent report says a new sewerage backbone pipeline must be built across the city. Even though modern sewerage systems are kept clean by an automated control system, residents still want the backbone pipeline placed as far from them as possible.

ICPC City is a well-planned, perfectly rectangular city whose four vertices are (L,B)(L, B), (L,T)(L, T), (R,T)(R, T), and (R,B)(R, B) for some L<RL < R and B<TB < T. The backbone pipeline must be a straight line that crosses the city, because it connects the neighboring regions on the two sides. We want the pipeline to lie as far as possible from everyone in the city. The population is given as a set of NN points Pi=(Xi,Yi)P_i = (X_i, Y_i) with L≤Xi≤RL \le X_i \le R and B≤Yi≤TB \le Y_i \le T.

For any line ll that passes through the city area, define the objective function

δ(l)=min⁡i=1,…,Nd(Pi,l),\delta(l) = \min_{i = 1, \dots, N} d(P_i, l),

where d(Pi,l)d(P_i, l) is the Euclidean (perpendicular) distance from point PiP_i to line ll. In other words, δ(l)\delta(l) is the smallest of the distances from all PiP_i to line ll.


Figure 1. Computing δ(l)\delta(l) for a given line ll through the city area.

An optimal backbone plan is a line l∗l^* that maximizes δ(l)\delta(l) over all lines ll that intersect the rectangle with vertices (L,B)(L, B), (L,T)(L, T), (R,T)(R, T), and (R,B)(R, B). Figure 2 shows three basic cases of an optimal plan l∗l^*.


Figure 2. Three basic examples.

Write a program that, given LL, RR, BB, TT, and the NN points PiP_i, finds the value δ(l∗)\delta(l^*) for an optimal backbone plan l∗l^*.

Input

The input is read from standard input. The first line contains the number of test cases KK (1≤K≤20)(1 \le K \le 20). Each test case is given as follows.

The first line of a test case contains four real numbers LL, RR, BB, TT (−1000≤L<R≤1000; −1000≤B<T≤1000)(-1000 \le L < R \le 1000;\ -1000 \le B < T \le 1000) that define the city area. The next line contains one integer NN (1≤N≤500)(1 \le N \le 500), the number of points. Each of the following NN lines contains two real numbers XiX_i and YiY_i, the XX-coordinate and YY-coordinate of point PiP_i, with L≤Xi≤RL \le X_i \le R and B≤Yi≤TB \le Y_i \le T.

Every real number is given with exactly three digits after the decimal point, and two numbers on the same line are separated by a single space.

Output

The output is written to standard output. For each test case, print exactly one line containing the value δ(l∗)\delta(l^*) for an optimal backbone plan l∗l^*. Print the value rounded to exactly three digits after the decimal point.

Examples3

  1. Example 1

    Input
    3
    0.000 10.000 0.000 10.000
    2
    0.000 0.000
    0.000 10.000
    0.000 10.000 0.000 10.000
    4
    0.000 0.000
    0.000 10.000
    10.000 0.000
    10.000 10.000
    0.000 3.000 0.000 4.000
    2
    0.000 0.000
    3.000 4.000
    
    Expected output
    10.000
    5.000
    2.500
    
  2. Example 2

    Input
    1
    0.000 10.000 0.000 10.000
    1
    5.000 5.000
    
    Expected output
    7.071
    
  3. Example 3

    Input
    1
    0.000 20.000 0.000 20.000
    4
    2.000 5.000
    2.000 15.000
    18.000 5.000
    18.000 15.000
    
    Expected output
    8.000