ÀÂÒ
Language: Russian
English

Remote Training on Programming

Problems Online status Contests
News FAQ E-learning
For authors:
Register  ||  Login
 
Hello, Guest! Please login or register.

477. Metal Cutting

Time Limit: 1 seconds
Memory Limit:65536KB
Points:100
View Problem Statistics Submit Problem added Undefined

In order to build a ship to travel to Eindhoven, The Netherlands, various sheet metal parts have to be cut from rectangular pieces of sheet metal. Each part is a convex polygon with at most 8 vertices. Each rectangular piece of sheet metal has width n and height m, so that the four corners of the sheet can be specified by the Cartesian coordinates (0,0), (0,m), (n,m), and (n,0) in clockwise order. The cutting machine available can make only straight-line cuts completely through the metal. That is,  it cannot cut halfway through the sheet, turn, and then cut some more. You are asked to write a program to determine the minimum total length of cuts this machine has to make in order to cut out the polygon.

 

For example, if n=m=100, and the polygon has vertices (80,80), (70,30), (20,20), and (20,80), the following diagram shows the optimal cut (the thick lines). The numbers show the order in which the cuts are made.

 

 

input

The first line of input contains the two integers n and m where 0<n,m<=500. The next line contains p, the number of vertices in the polygon, where 3<=p<=8. Each of the next p lines contains two integers x and y where 0<x<n and 0<y<m, specifying the vertices of the polygon. The vertices are listed in clockwise order. You may assume that the polygon does not

intersect itself, and that no three consecutive vertices are collinear.

 

output

Print the minimum total length of cuts required to cut out the given polygon accurate to 3 decimal places.

 

sample input

sample output

100 100

4

80 80

70 30

20 20

20 80

312.575

 

 


View Problem Statistics Submit Problem discussion Author/source:
Problems from Contests and Camps / Trainings of Vologda SU / VoSTU and VoSPU 17.11.2007 /
476. A - Keeps Going and Going and ... 477. 478. C - Parallel Deadlock 7. D - Reflections 479. E - Sorting Slides
time generating 0.094 sec.
© Copyright VSU, AVT, Nosov D.A., Andrianov I.A.