Safe Area
Time limit8sMemory limit512 MB
Given a rectangular screen, circular machine radius, and laser lines with thickness, decide if some circle center avoids all beams.
- Level
Medium6 of 10
- Topics
- Geometry, Implementation
- Solved
- No attempts yet
Problem
The screen is the rectangle whose lower left corner is and whose upper right corner is . The player moves a machine shaped as a circle of radius , and the machine has to stay completely inside the screen.
Enemies fire laser beams from outside the screen. A warning line is drawn a few seconds before a beam is fired along it, so the path of every beam is known in advance. The -th warning line is the infinite straight line through the two distinct points and , and the beam fired along that line covers every point whose distance to the line is at most .
The machine is destroyed once it overlaps a beam. A machine centred at therefore survives exactly when both of the following hold.
- and .
- For every , the distance from to the -th line is at least .
If at least one such position exists, the screen has a safe area. Given the warning lines and the radius of the machine, decide whether a safe area exists.
Input
The input is a sequence of datasets. Each dataset has the following format.
W H N R
x1,1 y1,1 x1,2 y1,2 t1
x2,1 y2,1 x2,2 y2,2 t2
...
xN,1 yN,1 xN,2 yN,2 tN
The first line contains four integers , , and (, , , ). and are the width and the height of the screen, is the number of laser beams, and is the radius of the machine.
The -th of the next lines contains the integer coordinates of two distinct points on the -th warning line, followed by the thickness of that beam (). Every coordinate is an integer point on the screen (, ). The centre of the machine may sit at non-integer coordinates.
There are at most 50 datasets, and the last line of the input is 0 0 0 0. Do not process that line.
In every dataset the answer stays the same if the radius of the machine grows by .
Output
For each dataset, print Yes on one line if a safe area exists, and No otherwise.