#P4529. [SCOI2003] 切割多边形

[SCOI2003] 切割多边形

Description

We wish to obtain a convex pp-gon, p8p\le 8.

Initially, you have an n×mn\times m rectangle; that is, its four corner coordinates are (0,0),(0,m),(n,0),(n,m)(0,0), (0,m), (n,0), (n,m). Each time, you may choose a straight line to cut the current shape into two parts and keep one part (discard the other). The length of a cut is defined as the length of the portion of this line that lies inside the polygon.

Find the minimal total length of all cutting lines.

Below is an example; we need to obtain the polygon in the middle.

Cut along lines 1,2,3,41, 2, 3, 4 respectively to obtain the quadrilateral in the middle.

Input Format

The first line contains two integers n,m (0<n,m<500)n,m\ (0 < n,m < 500).

The second line contains an integer p(3p8)p(3\le p\le 8), and each of the following pp lines contains two integers x,y(0<x<n,0<y<m)x, y(0 < x < n, 0 < y < m), which are the vertex coordinates given in clockwise order.

It is guaranteed that the polygon is convex, no three points are collinear, and the input is valid.

Output Format

Output a single line with the minimal total length of the cutting lines, rounded to 33 decimal places. An error of 0.0010.001 is allowed.

100 100
4
80 80
70 30
20 20
20 80
312.575

Hint

The sample corresponds to the example shown in the figure.

Translated by ChatGPT 5