Optimal fly

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
s₁ …s_(n) 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 a_(i) where the fly
stopped at the segments, in order. The first pair is the initial
position a₀, and the last pair is the final position a_(n + 1).

Assume 1 ≤ n ≤ 10⁴. Segments are different, and do not intersect. The
polygonal line a_(n + 1)…a₀ does not cross any segment. For all
1 ≤ i ≤ n, a_(i) is strictly inside the segment s_(i). The length of
each window and flight segment is strictly positive, and at most 1000.
No coordinate is larger than 10⁶ in absolute value.

Output

Print “yes” if the polygonal line a_(n + 1)…a₀ is the shortest path
between a_(n + 1) and a₀ that visits the segments s_(n)…s₁ in this
order. Print “no” otherwise.

Hint

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

Problem information

Author: Marc Vinyals

Generation: 2026-01-25T11:08:55.041Z

© Jutge.org, 2006–2026.
https://jutge.org
