Quiz questions often come up with similar logic questions, giving you a couple of cups of varying capacity to let you pour out how much water you have.
Android has a special game to play this topic called water Logic.
I install this game to dozens of levels pass again, feel the game design is not very good, the level of difficulty is not incremental, there are many behind the level of the mentally retarded, and the lack of difficult checkpoints.
As programmers, we should play such topics should be no problem, within 10 steps can easily be done, 10 steps or more can be done but may not be able to easily achieve the minimum number of steps.
Have 3 star obsessive-compulsive disorder player and programmer, write such an automatic solution of the small program, later this problem is no longer a problem.
Click here to try the cup water pouring problem automatically solve it
algorithm basic Logic :
Each cup is filled, emptied, poured into other cups operation, so the total is: Cup number * (number of cups -1+2)
For 3 cups, there are 12 different options for each step. If 2 cups have 6 kinds of optional operation each step.
Traverse each operation to record the amount of water in each cup after the operation is completed, and create a map by calculating a key to the amount of water.
The operation is discarded if the key already exists and the current step is greater than the number of previous records during the process of traversing a variety of inverted water operations.
This small program can only solve 2 cups or 3 cups of water pouring problem, and did not write N Cup general, the code has a lot of hard codes.