Problem C
Point in Polygon
Languages
da
en
You are given a simple polygon and a query point, and you wish to determine whether the query point is inside or outside the polygon.
In the 1st, 3rd, and 4th example below, the query point $q$ is “inside”; in the others it is “outside”.
Input
The input consists of:
-
One line with the coordinates $q_x$ and $q_y$ of the query point.
-
One line with the number $n$ of corners of the polygon, where $3\leq n\leq 100\, 000$.
-
$n$ lines, the $i$th of which contains the coordinates $x_i$ and $y_i$ of the $i$th corner for $1\leq i \leq n$.
Each coordinate is given as a floating point number. The $x$-coordinates satisfy $0\leq q_x, x_1,\ldots ,x_n\leq 180$. The $y$-coordinates satisfy $0\leq q_y, y_1,\ldots ,y_n\leq 90$.
It is guaranteed that the points are all different and that $(x_1,y_1),\ldots , (x_n,y_n), (x_1,y_1)$ (in this order) is a closed polygonal chain that forms the boundary of a simple polygon. Moreover, the query point $q$ has distance at least $10^{-6}$ from the boundary. Consequently, the query point is guaranteed to lie strictly inside or strictly outside the polygon.
Output
Write “inside” if $q$ is inside the polygon. Else write “outside”.
| Sample Input 1 | Sample Output 1 |
|---|---|
1.0 1.0 4 0.0 0.0 2.0 0.0 2.0 2.0 0.0 2.0 |
inside |
| Sample Input 2 | Sample Output 2 |
|---|---|
0.0 0.0 4 1.0 0.0 2.0 1.0 1.0 2.0 0.0 1.0 |
outside |
| Sample Input 3 | Sample Output 3 |
|---|---|
1.0 1.0 6 0.0 0.0 2.0 0.0 2.0 1.0 3.0 1.0 3.0 2.0 0.0 2.0 |
inside |
| Sample Input 4 | Sample Output 4 |
|---|---|
1.0 1.0 4 1.0 0.0 2.0 1.0 1.0 2.0 0.0 1.0 |
inside |
| Sample Input 5 | Sample Output 5 |
|---|---|
1.0 1.0 8 1.0 0.0 2.0 1.0 1.0 2.0 0.0 1.0 0.25 0.75 1.0 1.5 1.5 1.0 0.75 0.25 |
outside |
