#P10621. Optimal Map Tiling

    ID: 12647 Type: Default 1000ms 256MiB

Optimal Map Tiling

Optimal Map Tiling

Publishing maps is not an easy task. After projecting the Earth’s spherical surface onto a two‐dimensional plane, high-quality maps are often too large to be printed on a single sheet. To reduce printing costs, map publishers split the maps into several rectangular tiles printed on individual pages. In this problem, you are asked to help the International Cartographic Publishing Company (ICPC) determine the minimum number of tiles required to cover a given region.

The region is given as a simple polygon (i.e. a polygon that does not intersect itself) and the tiles form an infinite grid of fixed size, aligned with the $x$-axis and $y$-axis. Although all provided coordinates are integers, the grid can be shifted arbitrarily (tiles may be located at non-integer coordinates). Note that the polygon may touch the edges of some tiles. You may assume that the optimal answer will not change even if the polygon is allowed to go outside the map tiles by a distance of $10^{-6}$.

Your task is to choose the optimal grid translation so that the number of tiles intersecting the polygon is minimized, while keeping the tile size and orientation unchanged.

inputFormat

The first line of input contains two positive real numbers w and h, representing the width and height of each tile.

The second line contains an integer n (n ≥ 3) which is the number of vertices of the polygon.

The following n lines each contain two integers representing the x and y coordinates of the polygon's vertices given in order (either clockwise or counter-clockwise). The polygon is simple (its edges do not intersect, except at adjacent vertices).

outputFormat

Output a single integer representing the minimum number of grid tiles needed to cover the polygon.

sample

3 2
4
0 0
3 0
3 2
0 2
1