Take a stone game
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 35918 |
|
Accepted: 12140 |
Description have two piles of stones, which can be different in quantity. 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 Input
2 1
8 4
4 7
Sample Output
0
1
0
In game theory, the topics related to the Golden Section, which are listed after the case, observe the data, get the rules, find the 0,0 (3,5) (4,7) (6,10) (8,13) to find a law similar to the Golden section, and then, summed up a formula:
C=k* (1+SQRT (5))/2;c is the lesser value of a A, B.
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
using namespace std;
int main (void)
{
int a, b;
while (scanf ("%d%d", &a,&b)!=eof)
{
if (a>b)
{
int t;
T=a;
a=b;
b=t;
}
int k=b-a;
int c=k* (1+SQRT (5))/2;
if (c==a) printf ("0\n");
else
printf ("1\n");
}
return 0;
}