★[Game Theory] [Betty's theorem] chess game

Source: Internet
Author: User
Question Description: A and B take chess pieces from the two sets of chess pieces in turn to meet the following requirements: or take any number of (at least one) chess pieces from the pile, or retrieve the same number (at least one) of pawns from the two stacks, finish the two stacks and win the last one. Q: under what circumstances does a (first accessors) have a winning strategy? The input format is only one line. two integers separated by spaces are included to indicate the number of two heap pawns (each Heap has at least one and at most 10000 pawns ). The output format is only one line and contains one character. If the first accessor has a winning strategy, "Y" is output (excluding quotation marks); otherwise, "N" is output (excluding quotation marks ). [Example input 1] 1 [Example input 2] 5 3 [sample output 1] Y [sample output 2] n

Start with a simple situation.
Set n to the number of larger pieces, and m to the number of smaller pieces.
When n = 1, m = 2, it is easy to conclude that at this time it will be defeated.
Similarly, when (n, m) = (3, 5), (4, 7. The rest of the cases will win (because the opponent will be defeated by one step conversion ).
By betty's theorem,


The necessary conditions for defeat are:

Accode:

# Include <cstdio> # include <cmath> int main () {freopen ("Chess. in "," r ", stdin); freopen (" Chess. out "," W ", stdout); int n, m; scanf (" % d ", & N, & M); If (M> N) {int TMP = N; n = m; M = TMP;} printf ("% s \ n", INT (double (n-m) * (SQRT (5.l) + 1 .) /2 .) -M? "Y": "N"); Return 0 ;}

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.