Take a stone game
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K
Problem Description
There are two piles of stones, the quantity is arbitrary, can be different. 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
The input contains 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.
Output
The output corresponds to a number of lines, each containing a number 1 or 0, or 1 if you are the winner, or 0 for the other.
Sample Input
2 1
8 4
4 7
Sample Output
0
1
0
/* Witzov (Wythoff game): There are two piles of various items, two people take turns from a heap or at the same time from the two piles of the same number of items, the provisions of at least one at a time, more than unlimited, the last to win the light. In this case it is quite complicated. We use (AK,BK) (AK≤BK, k=0,1,2, ..., n) indicates the number of items in the two stacks and calls it a situation, if a face (0,0), then A has been lost, this situation we call the singular situation. The first few bizarre situations are: (0,0)、(1,2)、(3,5)、(4,7)、(6,Ten)、(8, -)、(9, the)、( One, -)、( A, -)。 As you can see, a0=b0=0, AK is the smallest natural number not appearing before, and bk= AK + K, the singular situation has the following three properties:1。 Any natural number is contained in one and only one singular situation. Since AK is the smallest natural number that has not been seen before, AK > ak-1, while bk= AK + k > ak-1+ K1= bk-1> ak-1。 So the nature1。 Was founded.2。 Any operation can transform the singular situation into a non-singular situation. In fact, if only one component of the singular situation (AK,BK) is changed, then the other component cannot be in other singular situations, so it must be a non-singular situation. If the two components of the (AK,BK) are reduced at the same time, it is also a non-singular situation because of its difference and the impossibility of being the difference between other singular situations.3。 The non-singular situation could be transformed into a singular situation by appropriate means. Assume that the situation is facing (a, b), if B =a, they are taken from both piles at the same time.aAn object, it becomes a singular situation (0,0); ifa= AK, B > BK, then take the B–bk object, which becomes a singular situation;a= AK, b < BK, while taking AK–AB + AK objects from both piles into a singular situation (Ab–ak, ab–ak+ B–ak);a> AK, b= AK + K, remove the excess quantity from the first heapa–ak, ifa< AK, b= AK + K, in two cases, the first type,a=aj (J < K), take b–bj from the second heap, and the second,a=BJ (J < k), take B – from the second pileaJ can. According to the nature of the above, two people if all use the correct operation, then face the non-singular situation, the first to win the winner; So let's give a situation (a, b), how do you judge if it is a singular situation? We have the following formula: AK =[k (1+√5)/2],bk= AK + k (k=0,1,2, ..., n square brackets represent the rounding function) The wonderful thing is that the number of golden Divisions appears (1+√5)/2=1。618..., so that the rectangle composed of AK,BK is approximated by a golden rectangle, as2/(1+√5) = (√5-1)/2, you can first find out the j=[a(√5-1)/2], ifa=[j (1+√5)/2], thena= AJ,BJ = AJ + j, if not equal, thena= aj+1, bj+1= aj+1+ j +1, if not, then it is not a singular situation. Then according to the above-mentioned law, we will encounter strange situation. situation (AK,BK) singular situation features: Ak =[k (1+√5)/2] bk= Ak + k (k=0,1,2, ... n square brackets denote rounding function) Conclusion: Bk-ak = k;if(Ak = = [k * (1+√5) /2]), the singular situation. Strange situation will be defeated * *
#include <bits/stdc++.h>Const DoubleData= ((sqrt(5)+1)/2.0);/* Situation (AK,BK) singular situation features: AK =[k (1+√5)/2] bk= AK + k (k=0,1,2,...n square brackets denote rounding function) Conclusion: Bk-ak = k;if (ak = = [k * (1 +√ 5)/2]), the singular situation. Strange situation will be defeated * *intMain () {intN,m; while(scanf("%d%d", &n,&m)!=-1){if(n>m) {n^=m^=n^=m; }BOOLans=false;intK=m-n;if(M==k+ (int) (K*data)) ans=true;printf("%d\n",!ans); }return 0;}
Take a stone game hdu1527