Cut a simple polygon with a line of given direction, keep the largest piece, and minimize that area over all line positions.
Medium7GeometryBinary searchImplementationNo attempts yetTime limit8sMemory limit512 MBMike Smith explores caves all over the world. One day a frightening creature blocked his way. He was scared, but he soon drew his knife and slashed at it. The creature split into parts, only the part with the largest area stayed, and the rest died out at once. Mike slashed a few more times until what was left was small enough for him to pass.
Turn the situation into the following problem. The creature is a simple polygon that may be convex or concave. Mike swings his knife along a straight line and cuts the creature with it. The direction of that line is given in the input, and Mike picks its position freely. One slash breaks the creature into pieces, and only the piece with the largest area stays.
Choose the position of the line so that the remaining area is as small as possible, and report that area. If the line runs through a vertex and two pieces meet at a single point, count them as two separate pieces.
The input holds several datasets. Each dataset has this format.
n
vx vy
x1 y1
...
xn yn
The first line holds the number of vertices n of the polygon that gives the shape of the creature (3≤n≤100). The second line holds two integers vx and vy, the direction vector (vx,vy) of the knife (−10000≤vx,vy≤10000, vx2+vy2>0). Each of the next n lines holds two integers xi and yi, the coordinates (xi,yi) of the i-th vertex (0≤xi,yi≤10000).
The vertices come in counterclockwise order. The polygon is always simple: two edges never touch and never cross except at a shared endpoint.
A line holding a single zero ends the input, and that line is not a dataset. The input holds at most 30 datasets.
For each dataset print the smallest possible area of the remaining piece on its own line, with exactly two digits after the decimal point. An area of 2 prints as 2.00. The judge data keeps every answer at least 0.002 away from a value where rounding to two decimals could go either way, so every solution with an absolute error below 10−3 prints the same digits.