Split a simple polygon into the largest number of equal-area vertical sections, each of area at least C, and print the bulkhead x-coordinates.
Medium7GeometryPrefix sumBinary searchNo attempts yetTime limit2sMemory limit512 MBA modern ship survives a collision because of its bulkheads, reinforced vertical walls inside the hull that keep water that has come in from spreading to other sections.
A design team finished the outline of the cross section of a new ship and left the bulkheads out. Placing them is your job.
The cross section is a simple polygon. A bulkhead is a vertical segment that cuts the whole cross section at one x-coordinate, so a set of bulkheads splits the cross section into vertical sections. Every section must have the same area, and that area must be at least C.
Find the largest number of sections M that can be made this way, then report where the bulkheads go.
The first line has an integer C (10≤C≤109), the minimum area of one section.
The second line has an integer N (3≤N≤105), the number of vertices of the outline.
Each of the next N lines has two integers x and y (−104≤x,y≤104), the coordinates of one vertex of the hull. The vertices come in counter-clockwise order.
The outline never doubles back on itself horizontally. A vertical line drawn anywhere passes through the cross section exactly once, never twice.
One section of area C always fits, and the number of sections M is between 1 and 100.
On the first line print M, the largest number of sections of equal area whose common area is at least C.
Then print M−1 lines. Line k holds the x-coordinate of the k-th bulkhead, placed so that all M sections have the same area. Print the coordinates in increasing order, each with exactly six digits after the decimal point.