(algorithm) Game win strategy

Source: Internet
Author: User
Topic:

1, Game 1:

There are two piles of coins, the number is variable (greater than 0), two people play the game, each time you can take any number of coins from any heap (greater than 0), who took the last coin is the winner.

2, Game 2:

A box, inside a certain number (greater than 0) of chocolate and a pepper, two people to play, each time you can take out 1 or 2 or 3 chocolate, pepper can only last take, who finally took the chili pepper will have to eat her, also lose.

Ideas:

Give the answer first:

Game 1:

If the number of coins is equal, let the other party take first, and then take the number of the pile of coins, so that the number of coins equal, in turn.

If the number of coins is not equal, then take the number of coins first, so that the number of coins is equal, and then let the other side to take, in turn.

Game 2:

If the number of chocolates is a multiple of 4, then let the other party take first, and then take it by themselves, the number is (4-the number of each other), in turn.

If the number of chocolates is not a multiple of 4, then let yourself take, take the quantity (the amount of chocolate%4), and then let the other side to take, and then take the number of their own, take the amount of (4-the number of the other), in turn.

Strategy Induction:

The two games have one thing in common: to find a point of balance.

If the initial state is balanced, then the other person comes first, letting him break the balance, and then to maintain the balance himself.

If the initial state is not balanced, then start by yourself, maintain the balance, then let the other person break, and then to maintain the balance.

Game 1 Balance: Two stacks of coins equal;

Game 2 Balance point: The number of chocolates is a multiple of 4;

Find the balance, you can determine the priority of the game and every step of the strategy, the winner's strategy is to continue to maintain the balance.

(algorithm) Game win strategy

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.