Sewerage Planning
Time limit1sMemory limit128 MB
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 , , , and for some and . 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 points with and .
For any line that passes through the city area, define the objective function
where is the Euclidean (perpendicular) distance from point to line . In other words, is the smallest of the distances from all to line .

Figure 1. Computing for a given line through the city area.
An optimal backbone plan is a line that maximizes over all lines that intersect the rectangle with vertices , , , and . Figure 2 shows three basic cases of an optimal plan .

Figure 2. Three basic examples.
Write a program that, given , , , , and the points , finds the value for an optimal backbone plan .
Input
The input is read from standard input. The first line contains the number of test cases . Each test case is given as follows.
The first line of a test case contains four real numbers , , , that define the city area. The next line contains one integer , the number of points. Each of the following lines contains two real numbers and , the -coordinate and -coordinate of point , with and .
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 for an optimal backbone plan . Print the value rounded to exactly three digits after the decimal point.