#C698. Line Segment Intersection

    ID: 50799 Type: Default 1000ms 256MiB

Line Segment Intersection

Line Segment Intersection

In this problem, you are given N line segments on a plane. Each segment is defined by four floating-point numbers representing the coordinates of its two endpoints: ( (x_1, y_1) ) and ( (x_2, y_2) ). Two segments ( (p_1, p_2) ) and ( (p_3, p_4) ) are considered to intersect if and only if [ \text{ccw}(p_1, p_3, p_4) \neq \text{ccw}(p_2, p_3, p_4) \quad \text{and} \quad \text{ccw}(p_1, p_2, p_3) \neq \text{ccw}(p_1, p_2, p_4), ] where the function ( \text{ccw}(a, b, c) ) determines whether three points make a counter-clockwise turn. Your task is to determine if any two of the provided segments intersect. Output YES if there exists at least one intersecting pair; otherwise, output NO.

inputFormat

The first line contains an integer ( N ) representing the number of line segments. Each of the following ( N ) lines contains four space-separated floating-point numbers: ( x_1\ y_1\ x_2\ y_2 ), which denote the endpoints of a segment.

outputFormat

Output a single line with the word YES if there exists any pair of intersecting segments; otherwise, output NO.## sample

4
0.0 0.0 1.0 1.0
0.0 1.0 1.0 0.0
1.0 0.0 2.0 1.0
1.0 1.0 2.0 0.0
YES