#P7471. Cake Cutting
Cake Cutting
Cake Cutting
Alice, Bob, and Cindy have a circular cake they wish to share. Their respective demands are given by non‐negative numbers \(a\), \(b\), and \(c\). The cake must be divided into pieces such that the areas given to Alice, Bob, and Cindy are in the ratio \(a:b:c\) (if any of \(a\), \(b\) or \(c\) is 0, that person does not receive any cake).
The cutting process is as follows:
- You may choose any diameter of the cake and cut along that line. (Note that a single cut along a diameter does not immediately separate the cake into two pieces.)
- If you make \(n\) cuts, you will obtain exactly \(2n\) wedge‐shaped pieces (with the special case \(n=0\) being considered as one piece, i.e. the entire circular cake).
- You must distribute these pieces among Alice, Bob, and Cindy. Each wedge can be given in full to exactly one person. By choosing the positions of the cuts arbitrarily, you can decide the angle (and therefore the area) of each wedge. However, the pieces cannot be subdivided further.
- The sum of the areas given to each person must be proportional to \(a\), \(b\), and \(c\), respectively. In other words, if the total angle is \(2\pi\), then the friend with demand \(a\) must receive an angle of \(\frac{2\pi a}{a+b+c}\) (and similarly for those with demand \(b\) and \(c\)).
Your task is to find the minimum number of cuts required to achieve the desired distribution.
Note: Because you can choose the angles of the wedges arbitrarily (as long as all wedges have a positive angle), what matters is the number of pieces obtained. In order to distribute the cake:
- If only one person has a positive demand (or all demands are 0), then the whole cake (1 piece) is sufficient, so 0 cuts are needed.
- If exactly two persons have positive demands, you need at least 2 pieces, which is achieved by making 1 cut (yielding 2 pieces).
- If all three persons have positive demands, you need at least 3 pieces. However, note that when \(n > 0\), the number of pieces is \(2n\), so the minimum number of pieces available is 4 (by making 2 cuts). It can be shown that with 4 pieces one can always partition them into 3 groups with positive sums. Therefore, in this case, 2 cuts are sufficient.
Thus, the answer is:
[ \text{min_cuts} = \begin{cases} 0, &\text{if at most one of }a,b,c \text{ is positive},\ 1, &\text{if exactly two of }a,b,c \text{ are positive},\ 2, &\text{if all of }a,b,c \text{ are positive}. \end{cases} ]
</p>inputFormat
The input consists of a single line containing three non-negative integers \(a\), \(b\), and \(c\) (each in the range \(0 \le a,b,c \le 10^9\)), separated by spaces.
outputFormat
Output a single integer indicating the minimum number of cuts required to divide the cake as specified.
sample
0 0 0
0