I Hate Raisins
Time limit1sMemory limit1024 MB
Given an X by Y by Z cake with one hidden unit raisin, find the fewest axis-parallel cuts that pinpoint the raisin's cell in the worst case.
- Level
Medium6 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
A cake shaped like a rectangular box has edge lengths , , and . Somewhere inside the cake is one raisin of unit size (). Treat the cake as a grid of unit-size cells. The raisin occupies exactly one of those cells. You are allergic to raisins, so before eating the cake, you decide to cut it and pinpoint the raisin's position. The cutting rules are as follows:
- A cut must be a plane parallel to the , , or axis, and it cuts through the entire plane.
- Rearranging the pieces after a cut is forbidden.
- A cut is allowed only if the result can be divided into unit-size pieces.
After cutting the cake zero or more times in this way, you can observe all surfaces of the resulting pieces. A cell is confirmed as the raisin cell even if only one of its faces is exposed.
You want to keep the cake as intact as possible, so you want to minimize the number of cuts. Using the best strategy, find the minimum number of cuts that pinpoints the raisin's position even in the worst case.
Input
The first line contains three integers , , and , separated by spaces. ()
Output
On the first line, print the minimum number of cuts needed to pinpoint the raisin's position in the worst case when using the best strategy.