
In the footsteps publishing tasks from the Algorithm track (classic competitive programming. You need to solve three problems in an hour and a half using Java, C#, C++, or Python.)
1. Cake for six
Task Definition
Time limit is 4 seconds.
You have a cake. When viewed from above, the cake has the shape of a (strictly) convex polygon. You are given the coordinates of the vertices in integers X and Y.
You have five friends. You want to divide the cake into six pieces of equal area (but not necessarily the same shape). Of course, anyone can do this with five cuts, but only a pro can do it with three cuts.
Find three cuts along straight lines through one point that divide the cake into six equal area pieces. Output {x, y, d1, d2, d3}, where (x, y) is the common point of all three cuts, and d1, d2, d3 are the angles of the cuts in radians.
DefinitionClass: CakeForSix
Method: cut
Parameters: int[], int[]
Returns: double[]
Method signature: double[] cut(int[] x, int[] y)
(be sure your method is public)
Notes
- Positive direction along the x-axis is 0 (radians), positive direction along the y-axis is pi/2 (radians).
- A cut in the direction d is analogous to a cut in the direction pi*k+d for any integer k.
- You can output any directions; they don't necessarily have to be from [0, pi).
- The grader will compute the areas of your six pieces of cake in doubles. The answer will be accepted if the relative or absolute difference between them is less than 10^(-4).
- More precisely, let X and Y be the smallest and largest of your six areas computed by the grader. Then your answer will be accepted if Y < max(X + 10^(-4), X * 1 + 10^(-4)).
- (In the original version of the problem, a precision of 1e-7 was used instead of 1e-4. To resolve this issue in the archive, the precision limit was lowered due to cases that likely make the problem unsolvable with a precision of 1e-7. In an ideal world, constraints do not allow such cases and still require high precision, so solving the problem with some general numerical optimization is not straightforward.)
Restrictions
- x contains from 3 to 50 elements inclusive.
- y contains the same number of elements as x.
- all coordinates between 0 and 10,000 inclusive
- x and y define a convex polygon in a counterclockwise direction.
Original in English
Problem Statement
Time limit is 4 seconds.
You have a cake. Viewed from above, the cake is a (strictly) convex polygon. You are given the coordinates of its vertices in the int[]s x and y.
You have five friends. You now want to cut the cake into six pieces of equal area (but not necessarily equal shape). Of course, anyone can do that in five cuts — but only a true pro can do it in three!
Find three straight-line cuts passing through the same point that divide the cake into six equally large parts. Return {x, y, d1, d2, d3}, where (x, y) is the common point of the three cuts, and d1, d2, d3 are their directions in radians.
Definition
Class: CakeForSix
Method: cut
Parameters: int[], int[]
Returns: double[]
Method signature: double[] cut(int[] x, int[] y)
(be sure your method is public)
Notes
— The positive direction along the x-axis is 0 (radians), the positive direction along the y-axis is pi/2 (radians).
— A cut in direction d is the same as a cut in direction pi*k+d for any integer k.
— You may return any directions, they do not have to be from [0,pi).
— The grader will compute the areas of your six cake pieces in doubles. The answer will be accepted if the relative or absolute difference between them is less than 10^(-4).
— More precisely, let X and Y be the smallest and the largest of your six areas, as computed by the grader. Then, your answer will be accepted if Y < max( X + 10^(-4), X * (1+10^(-4)) ).
— (The original version of the problem used 1e-7 precision instead of 1e-4. For upsolving this problem in the archive, the precision limit was lowered due to the existence of challenge cases that most likely make the task unsolvable with 1e-7 precision. In an ideal world, the constraints would not allow such cases and still require high precision, so that it isn’t easy to solve the problem via some general numeric optimization.)
Constraints
— x will contain between 3 and 50 elements, inclusive.
— y will have the same number of elements as x.
— All coordinates will be between 0 and 10,000, inclusive.
— x and y will describe a convex polygon in counterclockwise order.
Examples
0)
{0, 20, 30, 50, 30, 20}
{10, 0, 0, 10, 20, 20}
Returns:
{24.999999999437453, 9.999999999500002, 0.0, 0.7266423406817211, 2.4149503129080787 }
A symmetric but not regular hexagon. An example answer corresponds to cutting it in half horizontally and making two other cuts through the center, dividing each part into three pieces.

1)
{0, 1000, 0}
{0, 0, 1000}
Returns:
{333.3333333331763, 333.3333333332546, 0.7853981633986264, 2.0344439357948154, 2.6779450445891753 }
A right triangle. Again, we can start with one of the three cuts along the axis of symmetry.

2)
{40, 70, 90, 90, 50}
{30, 20, 40, 100, 60}
Returns:
{69.79517771922892, 52.77575974637605, 2.0616329654335885, 3.637826104091601, 4.32123485812475 }
An irregular pentagon.

3)
{300, 400, 300, 200}
{500, 600, 700, 600}
Returns: {299.99999999974995, 599.9999999995, 0.0, 1.107148717794088, 2.034443935795705 }
A square tilted 45 degrees.

[]
Only registered users can participate in the survey. , please.
I solved the task in
less than 10 minutes
10-30 minutes
30-60 minutes
1-2 hours
more than 2 hours
other
42 users voted. 47 users abstained.
Source: habr.com
