Sneaking Through the Corridor
Time limit5sMemory limit256 MB
Find the largest radius of a circle that can travel between two walls past circular sensors without entering any range.
- Level
Medium7 of 10
- Topics
- Union-find, Geometry, Binary search
- Solved
- No attempts yet
Problem
Seunghyun keeps his room under tight security. The only way in runs along a corridor packed with sensors, and a sensor sounds the alarm as soon as a person or an object enters its range.
Hyunseok is a very nimble spy. A client hired him to steal a classified document from Seunghyun's room, so he got hold of the corridor blueprint first. From the blueprint he has to decide whether he can walk in himself, and if he cannot, how small a robot he has to send instead.
Hyunseok treats the corridor as a plane. The two walls are the lines and , and sensor detects everything inside the circle with center and radius . A sensor sits against a wall or in the middle of the corridor. The object that travels down the corridor is a circle as well.
The object starts at and has to reach while staying inside the corridor. It must never enter the detection range of a sensor. Touching the boundary of a range is fine.
Given the sensor layout, find the largest radius of a circle that gets through the corridor without setting off an alarm.
Input
The first line has the number of test cases . ()
Each test case has this form.
- One line with the corridor width . () The two walls are the lines and .
- One line with the number of sensors . ()
- lines with integers , , , the center of a sensor and the radius of its range. (, , )
The corridor runs forever along , and the end the object starts from and the end it leaves through are both far outside every sensor range.
Output
For each test case print on its own line the largest radius of a circular object that passes the corridor undetected. Assume the object moves with unlimited precision. Print when nothing can get through.
Round the answer to six decimal places and always print all six digits after the point. An answer of prints as 1.500000, and an answer of prints as 0.000000.