Optimal fly P61365


Statement
 

pdf   zip

html

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 n. Follow the description of the s1sn segments, in the order the fly visits them, each with two pairs (x, y) with the coordinates of its two endpoints. Follow n+2 pairs (x, y) with the coordinates of the points ai where the fly stopped at the segments, in order. The first pair is the initial position a0, and the last pair is the final position an+1.

Assume 1 ≤ n ≤ 104. Segments are different, and do not intersect. The polygonal line an+1a0 does not cross any segment. For all 1 ≤ in, ai is strictly inside the segment si. The length of each window and flight segment is strictly positive, and at most 1000. No coordinate is larger than 106 in absolute value.

Output

Print “yes” if the polygonal line an+1a0 is the shortest path between an+1 and a0 that visits the segments sns1 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++
    Event
    Tretzè Concurs de Programació de la UPC - Final
    Date
    2015-09-16