【HDU】Wizov Game

Picking stones game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10002    Accepted Submission(s): 5778

 

Problem Description

There are two piles of stones, the number of which can be different. The game begins with two people taking turns taking stones. The game stipulates that there are two different ways to take each time. One is that you can take as many stones as you want from any pile; the other is that you can take the same number of stones from two piles at the same time. In the end, the one who removes all the stones is the winner. Now given the initial number of two piles of stones, if it is your turn to take first, assuming both sides take the best strategy, ask whether you are the winner or the loser in the end.

Input

The input contains several lines, representing the initial conditions of several kinds of stones, each line contains two non-negative integers a and b, representing the number of two piles of stones, a and b are not greater than 1,000,000,000.

Output

The output also has several lines, each line contains a number 1 or 0, if you are the winner in the end, it is 1, otherwise, it is 0.

Sample Input

2 1

8 4

4 7

Sample Output

0

1

0

problem analysis:

1. There are two piles of stones, any number

2. There are two different ways of taking each time: one is that you can take as many stones as you want from any pile; the other is that you can take the same number of stones from two piles at the same time.

3. The winner is the one who gets all the stones at the end.

Wyzhov game, the state of two piles of stones is [ak,bk] (satisfying ak<=bk), when ak=(k*(√5+1)/2), bk=ak+k, the singular situation is satisfied, then then The first to lose, otherwise the first to win:

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    long long a,b;
    while(cin>>a>>b)
    {
        if(a>b){
            long long t=a;a=b;b=t;
        }
        long long k=b-a;
        double x=(sqrt(5)+1)/2;
        if(a==(long long)(k*x))
            cout<<0<<endl;
        else
            cout<<1<<endl;
    }
}

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327103355&siteId=291194637