#P5938. Temple Desecration
Temple Desecration
Temple Desecration
In a sacred architectural complex, temples are constructed as axis‐aligned rectangles. Each temple is built such that its sides are parallel to the north, south, east, and west directions. Two temples are guaranteed not to share any common points. One special temple is given an entrance located at the center of one of its four walls. The door width is exactly half the length of that wall. An altar is installed at the center of the temple – the intersection point of the diagonals. A ghost appears at the altar. The temple is said to be desecrated if and only if there exists a ray (i.e. a half–infinite straight line) emanating from the altar, passing through the center of the door, and reaching infinity without intersecting or even touching any wall of any other temple. In mathematical terms, if we denote the altar by ( A ) and the door center by ( D ), then the ray is given by ( A + t(D-A) ) for ( t \ge 0 ). For any other temple with a rectangular boundary, if this ray intersects (or touches) any segment of its perimeter (where the endpoints are excluded, i.e. the intersection must occur strictly within an edge), then the ray is blocked. Your task is to determine whether the special temple is desecrated.
Note: The temple’s own walls are not considered as obstacles. Only the walls of other temples in the building region (all of which are axis–parallel rectangles) matter.
inputFormat
The first line of input contains a single integer ( T ) (1 ( \le T \le 10^5 )), the number of temples. Each of the following ( T ) lines describes a temple with five tokens: four real numbers ( x_1 ), ( y_1 ), ( x_2 ), ( y_2 ) (with ( x_1 < x_2 ) and ( y_1 < y_2 )) representing the coordinates of the bottom–left and top–right corners of the temple, and a character. For the special temple (the one under test) the character is one of 'N', 'S', 'E', or 'W', indicating that the entrance is located respectively at the middle of the North, South, East, or West wall. For every other temple, this character will be a dash '-' (without quotes). It is guaranteed that exactly one temple has an entrance (i.e. its door indicator is not '-').
outputFormat
Output a single line containing “YES” if the special temple is desecrated, or “NO” otherwise.
sample
1
0 0 4 4 N
YES
</p>