Take a stone game

Source: Internet
Author: User

Time limit:2000/1000ms (java/other) Memory limit:20000/10000k (Java/other) total submission (s): 1 Accepted Submiss Ion (s): 1Problem description has two piles of stones, which can be different in number. The game began with two people taking turns to take stones. The game rules, each time there are two different ways, one can take away any number of stones in any heap, and two can take the same number of stones in both piles. Finally, the stones are all taken out as the winner. Now give the number of the initial two piles of stones, if it's your turn to take it first, assume that both sides adopt the best strategy and ask whether you are the winner or the loser. Input inputs contain several lines that represent the initial condition of several kinds of stones, each of which contains two nonnegative integers a and B, indicating the number of stones, A and B, not greater than 1,000,000,000. The output outputs correspond to several lines, each containing a number 1 or 0, or 1 if you are the winner, or 0 for the other. Sample Input2 7 Sample Output010 Sourcepku 

The so-called Witzov game, is one of the common combination games in ACM problem, is basically this:
There are two piles of stones, you may think of a pile of 10, another pile of 15, the two sides take some stones in turn, the legal way has the following two kinds:
1, in a heap of stones to take away any number of;
2. Take the same number of free stones in two piles;
Agreed to take the last stone of the man-made winner, to win the strategy.

The two piles of stone status are the same, we use the remaining stone number (a, a, b) to represent the State, and drawn in a plane Cartesian coordinate system.

Similar to the previous one, (0,0) must be P-state, also known as the state of defeat. (0,k), (k,0), (k,k) series of nodes is certainly not P-state, but to win the state, you face such a situation will certainly win, as long as the rules to take once on it. Then see y = the lattice point that is not crossed above X, which is P-state. K > 2 o'clock, (1,k) is not P-state, such as if you face (1,3) situation, you are likely to win. Similarly, (k,2), (1 + k, 2 + K) are also not P-states, and the points are crossed and their symmetry points, and then find the remaining points above y = x, and you will find (3,5) A P-state, so that if we only find a≤b P-states, then they are (0,0), (3,5), (4,7), (6,10) ... Do they have any rules?

Ignoring (0,0), you will soon find a,a = i * (sqrt (5) + 1)/2 and then rounding for the P-state of I, and B = A + I. It's got a relationship with the golden divide.
The first few defeats are as follows: (0,0), (3,5), (4,7), (6,10), (8,13) ... It can be found that for the K-points (M (k), N (k)), M (k) is the smallest natural number not previously seen, N (k) =m (k) +k.
Judging whether a point is a must-fail formula is related to the Golden section (I can't give a strict mathematical proof, who can give a strict mathematical proof remember to tell me), for:
M (k) = k * (1 + sqrt (5))/2
N (k) = m (k) + K;

#include <iostream> #include <cstdio> #include <cstring> #include <cmath>using namespace std; int A,b;int Main () {    //freopen ("Input.txt", "R", stdin);    while (~SCANF ("%d%d", &a,&b)) {        if (a<b) {            a^=b;            B^=a;            a^=b;        }        int k=a-b;        a= (int) (K* (1+SQRT (5))/2.0);        if (a==b)            printf ("0\n");        else            printf ("1\n");    }    return 0;}


Take a stone game

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.