Optimal fly P61365


Statement
 

pdf   zip

A fly just travelled between two points in the plane, stopping at several windows (segments) on its way. The fly does not have a very big brain, but it is powerful enough to fly in a straight line between stops. Now the fly wants to go back and visit the windows in reverse order, but it is still worried about efficiency. Is the reverse path optimal? Please help the fly with your bigger brain.

Input

Input consists of several cases, which only have integer numbers. Every case begins with the number of segments nn. Follow the description of the s1s_1sns_n segments, in the order the fly visits them, each with two pairs (x,y)(x, y) with the coordinates of its two endpoints. Follow n+2n+2 pairs (x,y)(x, y) with the coordinates of the points aia_i where the fly stopped at the segments, in order. The first pair is the initial position a0a_0, and the last pair is the final position an+1a_{n+1}.

Assume 1n1041 \le n \le 10^4. Segments are different, and do not intersect. The polygonal line an+1a0a_{n+1} \ldots a_0 does not cross any segment. For all 1in1 \le i \le n, aia_i is strictly inside the segment sis_i. The length of each window and flight segment is strictly positive, and at most 10001000. No coordinate is larger than 10610^6 in absolute value.

Output

Print “yes” if the polygonal line an+1a0a_{n+1} \ldots a_0 is the shortest path between an+1a_{n+1} and a0a_0 that visits the segments sns1s_n \ldots s_1 in this order. Print “no” otherwise.

Hint

All the required computations can be made with long longs without overflows.

Public test cases
  • Input

    1
    500 0  500 100
    0 0
    500 50
    0 100
    
    1
    500 0  500 100
    0 0
    500 50
    0 50
    

    Output

    yes
    no
    
  • Information
    Author
    Marc Vinyals
    Language
    English
    Official solutions
    C++
    User solutions
    C++