Share the Cakes
Time limit2sMemory limit128 MB
Given two disjoint convex polygons, find the single line that simultaneously bisects the area of both, and output its slope and intercept scaled by 1e6.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search, Divide and conquer, Math
- Solved
- No attempts yet
Problem
Lunar was born on the day of the Mid-autumn Festival, so every birthday she gets two cakes, a birthday cake and a moon cake.
This year Lunar wanted to share both cakes with her boyfriend Jaddy. She put the two cakes on the table and asked him to cut them, because she wanted half of the birthday cake and half of the moon cake. Jaddy took one lazy swing of the knife and cut through both cakes at once. Each cake ended up in two pieces, but neither cake was split into equal halves. Lunar got angry and left him.
Jaddy regretted it badly, so Lunar gave him one more chance. The restriction did not change. He may use only one cut, and that single cut has to divide both cakes into equal halves.
Both cakes are convex polygons. The table is an infinite plane and the blade is an infinite line. Find the line that bisects the area of both cakes at the same time.
Input
The first line contains the number of test cases ().
Each test case describes two cakes as two convex polygons. Each polygon starts with its number of vertices (), followed by lines that give the coordinates and of the vertices in counterclockwise order. All coordinates are integers between and .
The two polygons of a test case can be separated by a line, and no point of either polygon lies on that line.
Output
Print one line for each test case. Let be the line Jaddy has to cut along, let be the integer nearest to , and let be the integer nearest to . Print the two integers together with the test case number in this format.
Case #i: K B
The numbering starts at 1.
In every test case exactly one line bisects both cakes, and that line is not parallel to the axis. Also and , and each of and differs from its nearest integer by at most , so the rounding is never in doubt.