#P8216. THUPC Logo Verification
THUPC Logo Verification
THUPC Logo Verification
The THUPC logo is generated by an "artificial intelligence" that only draws horizontal and vertical line segments. The logo is composed of five letters: T, H, U, P, C. After merging collinear (i.e. same orientation) segments that are connected (overlapping, touching or one inside the other) into single segments, the final set must exactly contain 15 segments. Each segment is given as follows:
- For a horizontal segment, its coordinates are \( [l_i, r_i] \) along the x\ndash;axis with constant y = \(y_i\) (with \(r_i > l_i\)).
- For a vertical segment, its coordinates are \( [d_i, u_i] \) along the y\ndash;axis with constant x = \(x_i\) (with \(u_i > d_i\)).
The letters are built from the following numbered segments after reordering:
- T is made of segments 1 (horizontal) and 2 (vertical) satisfying
\( d_2 < y_1 = u_2 \) and \( l_1 < x_2 < r_1 \). - H is made of segments 3 (vertical), 4 (horizontal) and 5 (vertical) satisfying
\( d_3 = d_5 < y_4 < u_3 = u_5 \) and \( x_3 = l_4 < r_4 = x_5 \). - U is made of segments 6 (vertical), 7 (horizontal) and 8 (vertical) satisfying
\( d_6 = d_8 = y_7 < u_6 = u_8 \) and \( x_6 = l_7 < r_7 = x_8 \). - P is made of segments 9 (vertical), 10 (horizontal), 11 (horizontal) and 12 (vertical) satisfying
\( d_9 < y_{11} = d_{12} < u_9 = y_{10} = u_{12} \) and \( x_9 = l_{10} = l_{11} < r_{10} = r_{11} = x_{12} \). - C is made of segments 13 (vertical), 14 (horizontal) and 15 (horizontal) satisfying
\( d_{13} = y_{15} < u_{13} = y_{14} \) and \( x_{13} = l_{14} = l_{15} < r_{14} = r_{15} \).
The five letters can be positioned arbitrarily on the plane (i.e. they need not be arranged left to right), but no segment from one letter may intersect any segment from a different letter. Here, two segments are considered intersecting if they share even a single point.
Your task is to write a program that, given a set of line segments, first merges any collinear connected segments (i.e. segments in the same direction and sharing endpoints or overlapping), then checks whether exactly 15 segments remain and they can be connected and re‐ordered to form a valid THUPC logo according to the above rules. Output YES
if the generated logo is correct, or NO
otherwise.
Note:
- The order of segments in the input may be arbitrary.
- The input may contain extra segments or may be missing some segments, both cases are considered invalid.
inputFormat
The input begins with an integer n
indicating the number of line segments.
Then follow n
lines. Each line describes a segment in one of the two formats:
H l r y
for a horizontal segment (with integer coordinates and \(r > l\)).V d u x
for a vertical segment (with integer coordinates and \(u > d\)).
You should merge any collinear, connected segments (i.e. segments with the same orientation and constant coordinate where their intervals overlap or touch) into one segment before further processing.
outputFormat
Output a single line containing YES
if the merged and re‐ordered segments form a valid THUPC logo according to the rules, or NO
otherwise.
sample
15
H 5 15 10
V 0 10 10
V 5 15 20
H 20 30 10
V 5 15 30
V 10 20 40
H 40 50 10
V 10 20 50
V 5 15 60
H 60 70 15
H 60 70 8
V 8 15 70
V 2 12 80
H 80 90 12
H 80 90 2
YES