POJ 1067| | Hdu 1527 Take the Stone game (game theory, Wythoff game)

Source: Internet
Author: User

Take a stone game
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 37893 Accepted: 12684

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 18 44 7

Sample Output

010

Source

Noi reproduced a section of explanation:

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.

Join in a bunch of words, you can take any heap, then the difference is also uncertain, but we can enumerate the difference, the difference is 0---large number of stones, and then according to the above theory to determine the satisfaction of the condition is a reasonable method.

/************************************************************************* > File name:code/hdu/1527.cpp > AUTHOR:111QQZ > Email: [email protected] > Created time:2015 October 01 Thursday 20:26 40 seconds ************************ ************************************************/#include<iostream>#include<iomanip>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>#include<map>#include<Set>#include<queue>#include<vector>#include<stack>#include<cctype>#defineY1 HUST111QQZ#defineYn hez111qqz#defineJ1 CUTE111QQZ#defineMS (A,X) memset (A,x,sizeof (a))#defineLR DYING111QQZusing namespacestd;#definefor (i, n) for (int i=0;i<int (n); ++i)typedefLong LongLl;typedefDoubleDB;Const intINF =0x3f3f3f3f;intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif   intb;  while(SCANF ("%d%d", &a,&b)! =EOF) {      if(a<b) Swap (A, a); intTMP =a-b; if(b==int(Tmp* (sqrt (5)+1)/2) {puts ("0"); }       Else{puts ("1");  }} #ifndef Online_judge fclose (stdin); #endif    return 0;}

  

POJ 1067| | Hdu 1527 Take the Stone game (game theory, Wythoff 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.