Given a rectangular screen, circular machine radius, and laser lines with thickness, decide if some circle center avoids all beams.
Medium6GeometryImplementationNo attempts yetTime limit8sMemory limit512 MBThe screen is the rectangle whose lower left corner is (0,0) and whose upper right corner is (W,H). The player moves a machine shaped as a circle of radius R, 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 i-th warning line is the infinite straight line through the two distinct points (xi,1,yi,1) and (xi,2,yi,2), and the beam fired along that line covers every point whose distance to the line is at most ti.
The machine is destroyed once it overlaps a beam. A machine centred at (x,y) therefore survives exactly when both of the following hold.
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.
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 W, H, N and R (2<W≤640, 2<H≤480, 0≤N≤100, 0<R<min(W,H)/2). W and H are the width and the height of the screen, N is the number of laser beams, and R is the radius of the machine.
The i-th of the next N lines contains the integer coordinates of two distinct points on the i-th warning line, followed by the thickness ti of that beam (0≤ti≤1000). Every coordinate is an integer point on the screen (0≤x≤W, 0≤y≤H). 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 10−5.
For each dataset, print Yes on one line if a safe area exists, and No otherwise.