Polygon Guards
Time limit5sMemory limit128 MB
Place the fewest guards on vertices of an orthogonal simple polygon with under 40 vertices so every vertex is visible from a guard.
- Level
Hard8 of 10
- Topics
- Geometry, Brute force, Bit manipulation, Graph
- Solved
- No attempts yet
Problem
You are an IT system administrator in the Ministry of Defense of Polygon Country.
The border of Polygon Country is a polygon with vertices. Drawn on the plane, every vertex sits on a lattice point and every edge is parallel to the axis or the axis.
To keep enemies out, a very strong defense wall runs along the whole border. A vertex is where two walls meet, so it has a structural weakness that cannot be removed. Enemies therefore attack and invade at the vertices.
To watch the vertices and notice an invasion as early as possible, the ministry decided to hire guards. Guards stand on vertices only, and they are placed so that every vertex is watched by at least one of them. A guard at vertex can watch vertex if the whole segment joining and lies inside the polygon or on its edges. A guard also watches the vertex he or she stands on. One guard watches every vertex he or she can watch at the same time.
The ministry wants to cut the defense cost, so it wants the number of guards to be as small as possible. Compute the minimum number of guards needed to watch all vertices of Polygon Country.
Input
The input is formatted as follows.
N
X1 Y1
:
:
XN YN
The first line contains an even integer ().
Each of the next lines describes one vertex of the polygon with two integers and separated by one space (, , ). The -th vertex is at .
If is odd, then and . If is even, then and . Here and .
The vertices are given in counterclockwise order in the coordinate system where the axis points right and the axis points up. The polygon is simple, so an edge shares no point with any other edge except the endpoints it shares with its two neighbors.
Output
Print the minimum number of guards on one line.