Hdu1846 classic game theory

Source: Internet
Author: User

Today, I am engaged in game theory! Start with the most classic game theory!

There are n stones in a pile, and a and B take turns (1 ~ M) a rock. It is required that a should take the first stone and win the light first (that is, the person who takes the last stone wins ), both parties are smart enough (both parties adopt the best decision-making strategy ).

Given n, m asked who can win.

First look at some instances: If m = 2; then n = 1, n = 2, A can directly win. When n = 3, Jia will lose whatever he gets. When n = 4, 5, Jia can take one piece first, and then there are more than 2 stones left. Therefore, Jia still has the opportunity to take it again, and take the remaining light. When n = 6, it is found that a will lose no matter how he gets it.

After some examples, we can draw some conclusions: If n is less than or equal to m, then Jia wins.

If a is an integer multiple of (m + 1) after a request is obtained, a can take control of the entire game and win the game. Next, if B gets k blocks, a will take m + 1-k blocks, and a will ensure that they get m + 1 blocks in each round, so that they can loop in sequence, until the last group of m + 1 stones is left, it is B's turn to take the stones. Because the remaining number of stones is m + 1, B cannot play, then, Jia can play and win the game.

Therefore, if n % (m + 1) is not 0, that is, if A is equal to an integer multiple of m + 1 after a is obtained, a wins. Otherwise, B wins.

This is the basic application of the legendary Bashi game.

 

 

Related Article

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.