#P5696. Camera Surveillance

    ID: 18924 Type: Default 1000ms 256MiB

Camera Surveillance

Camera Surveillance

Given a room represented as a simple closed polygon (each edge representing a wall), your task is to determine whether there exists a position inside the room to place a single camera such that every corner (vertex) of the room is visible from that camera.

Mathematically, a point \(P\) inside a polygon \(\mathcal{P}\) is said to see a vertex \(V\) if the line segment \(PV\) lies entirely within \(\mathcal{P}\). We require that there is at least one point \(P\) from which every vertex is visible. This is equivalent to testing whether the kernel of the polygon is non-empty. The kernel is defined as the intersection of the half-planes determined by each edge of the polygon, where each half-plane contains the interior of the polygon. In formula, if an edge is defined by points \(A\) and \(B\), and the polygon orientation is determined by its signed area \(\Delta\), then for a point \(P\) the condition is given by:

[ \begin{cases} \vec{AB} \times \vec{AP} \ge 0, & \text{if } \Delta > 0,\ \vec{AB} \times \vec{AP} \le 0, & \text{if } \Delta < 0. \end{cases} ]

If the kernel is non-empty, output YES; otherwise, output NO.

inputFormat

The input consists of:

  1. An integer n (3 ≤ n) representing the number of vertices of the polygon.
  2. n lines follow, each containing two integers x and y, representing the coordinates of the vertices in order (either clockwise or counter-clockwise).

outputFormat

Output a single line containing YES if there exists a point within the polygon from which every vertex is visible; otherwise, output NO.

sample

4
0 0
10 0
10 10
0 10
YES