ZOJ Problem Set - 3720
There is a magnet board on the wall, and you can throw magnet darts towards it. When a magnet dart hit a point (x, y), because of the magnetism, it will be pulled to the nearest integer point (x', y'), and you can get a score of Ax' + By'.
To make the game more interesting, only the integer points in the given N-polygon (or on the border) could get score. And we assume all the throw must hit a point which is in a rectangle area, and the polygon is also in the rectangle. Your task is to calculate the average expectation of score per throw.
There are multiple test cases. For each test case:
The first line contains four real numbers P0, Q0, P1, Q1 (0≤P0<P1≤500, 0≤Q0<Q1≤500), represents the lower left point and the upper right point of the rectangle area, all the throw must hit a point in it.
The second line contains three integers N (3≤N≤20), A, B (-100≤A, B≤100). The meaning of them is in the description above.
Next N lines, each line contains two intergers Xi, Yi, represents the ith vertex of the polygon by clockwise order, we promise each vertex is in the rectangle area.
There is a blank line between every two cases.
One line for each case. The the average expectation of score per throw with three decimal places.
0 0 4 3 3 1 1 2 3 4 2 3 0
A throw hit a point which is outside the polygon may be pulled in it and get score.
Author: LI, Huang
Contest: ZOJ Monthly, June 2013