Use the progressive method to solve simple classification problems

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.