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.
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.
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.
Problem: First there are two piles of stones, the game each can take a heap of stones in any one, not to take, or take two of the same stone. Take the winner first.
Analysis: First we analyze the singular situation in the game according to the condition
The first (0, 0), the initiator loses, when the game on a certain aspect (0, 0), he has no way to take, then must be the initiator in the last inning, then lose.
The second (1, 2), the initiator loses, the initiator only has four kinds of extraction,
1) Take one of the 1, then take the second pile of two.
2) Take one of the 2, then one in each of the two piles.
3) Take two in 2, then the next one in the first heap.
4) Take one in each of the two piles, then the next one in the second heap.
It can be seen that no matter how the tempo is taken, it is always possible to win. So the initiator will lose!
The third one (3, 5), the initiator will lose. First of all, you must not take any of the heap to finish, if it is clear that the next hand to take out another pile of the initiator will lose, then
If you look at a bunch of situations, assume that the initiator first takes it in the first heap. Take 1, the second in the next pile to take 4, become (1, 2), the above analysis is the initiator will lose the bureau.
Take 2, and take 3 in the second pile, also become (1, 2) situation.
Assuming that the initiator in the second heap to take, take 1, then the two in both piles to take 2, also become (1, 2) situation.
Take 2, then the back can be two piles to go to three, into (0, 0) situation, the above analysis will lose.
Take 3, two to 1 each, into the (1, 2) situation.
Take 4, the next one in the first heap, into the (1, 2) situation.
Visible no matter how to take the initiator, it will lose!
The fourth one (4, 7), the initiator will lose.
Their own reasoning can be found no matter how to take the first time, then the front will always be turned into the previous analysis of the initiator must lose the situation.
So what's the rule no, we continue to write down.
Fourth one (6, 10)
Fifth one (8, 13)
Sixth one (9, 15)
Seventh one (11, 18)
Will find their difference is incremented for 0, 1, 2, 3, 4, 5, 6, 7.....N
And the mathematical method of analysis found that the first value in the situation before the first value, such as the third situation, preceded by 0 1 2, then the first value of the third situation is 3, such as the fifth situation, the former
Polygons appeared 0 1 2 3 4 5, then the fifth situation the first value is 6.
If we look at the rules again, we'll find that the first value = difference * 1.618
and 1.618 = (sqrt (5) + 1)/2.
We all know that 0.618 is the golden ratio. And Witzov game is just 1.618, this is the magic of the game!
Here's a look at three common types of Witzov game problems:
1) give you a situation, so that you want to win or lose.
With the above analysis, the problem should not be difficult to solve. First of all, the value of travel, the difference * 1.618 = = minimum value, then win, otherwise the initiator wins. (Note that the 1.618 here is best calculated using the above formula, otherwise fine
The subject of a high degree of demand will be wrong)
2) give you a situation, let you seek to win the winner, assuming that the winning words output his first time the extraction.
The first discussion on both sides at the same time, it is obvious that both sides at the same time, no matter how to take his difference is not changed, then we can calculate the difference between the small value, and then add the difference is a large value, when
The condition that can be obtained is that the minimum value can not be greater than the number of pebbles in the small heap.