首页 > ACM题库 > HDU-杭电 > HDU 4203-Doubloon Game-数论-[解题报告]HOJ
2015
05-23

HDU 4203-Doubloon Game-数论-[解题报告]HOJ

Doubloon Game

问题描述 :

Being a pirate means spending a lot of time at sea. Sometimes, when there is not much wind, days can pass by without any activity. To pass the time between chores, pirates like to play games with coins.
Ultimate Finishing Strike

An old favorite of the pirates is a game for two players featuring one stack of coins. In turn, each player takes a number of coins from the stack. The number of coins that a player takes must be a power of a given integer K (1, K, K^2, etcetera). The winner is the player to take the last coin(s).
Can you help the pirates gure out how the player to move can win in a given game situation?

输入:

The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
One line with two integers S and K, satisfying 1 <= S <= 10^9 and 1 <= K <= 100: the size of the stack and the parameter K, respectively.

输出:

The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
One line with two integers S and K, satisfying 1 <= S <= 10^9 and 1 <= K <= 100: the size of the stack and the parameter K, respectively.

样例输入:

5
5 1
3 2
8 2
50 3
100 10

样例输出:

1
0
2
0
1

博弈题。。?这tm根本就是一道数论题!!f*。。

#include<iostream>
#include<vector>
using namespace std;

int n,k;

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n>>k;
        if(k%2)
        {
            if(n%2)
            {
                cout<<"1"<<endl;
            }
            else
            {
                cout<<"0"<<endl;
            }
        }
        else
        {
            if(n%(k+1)==k)
            {
                cout<<k<<endl;
            }
            else if((n%(k+1))%2)
            {
                cout<<"1"<<endl;
            }
            else
            {
                cout<<"0"<<endl;
            }
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/zz_1215/article/details/7527616