This problem was found at the programmer's forum, but the original question was not clearly described. I changed it:
There are n peaches, and two monkeys have a small one. The two monkeys take the peaches in turn, and each monkey can only take 1 ~ Three, and the monkeys take them first. The winner has an even number of peaches. The problem is whether the monkey has a winning strategy given a positive integer n.
In fact, the solution to the problem is very simple. If n is small, to what extent? If it is equal to 1, it indicates that the monkey cannot win, because it also needs to take at least one and it is over. When N is small, the result is obvious:
N |
Can a monkey win? |
1 |
No |
2 |
Yes |
3 |
Yes |
4 |
Yes |
N = 4 is a special case. If there are three monkeys, the next big monkey can only face one peach, and n = 1 is a defeat, so when n = 4, the monkey will be able to win.
the next step is to understand that when n = 5, no matter how the monkey gets it, the next big monkey will face a strategy to win, so the monkey cannot win. After this recurrence, we can conclude that when n mod 4 = 1, the monkey has no strategy to win.