HDU4203 Doubloon Game博弈+规律

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU4203 Doubloon Game博弈+规律相关的知识,希望对你有一定的参考价值。

Doubloon Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1043 Accepted Submission(s): 580

Problem Description
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.

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?

Input
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.

Output
For every test case in the input, the output should contain one integer on a single line: the smallest number of coins that the player to move can take in order to secure the win. If there is no winning move, the output should be 0.

Sample Input
5
5 1
3 2
8 2
50 3
100 10

Sample Output
1
0
2
0
1

Source
BAPC 2011

问题链接HDU4203 Doubloon Game
问题简述:给定s个石子和整数k,每次只能取k幂次的石子数,例如:1,k,k2,k3,…,谁先取完谁赢。问先手获胜的话, 第一次最少拿几块石头?不能获胜则输出0。
问题分析:博弈的SG函数问题,打表找规律,根据规律写解题程序。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* HDU4203 Doubloon Game */

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t, s, k;
    scanf("%d", &t);
    while(t--) {
        scanf("%d%d", &s, &k);
        int x = s % (k + 1);
        if (k & 1 || x < k) puts(x & 1 ? "1" : "0");
        else printf("%d\\n", k);
    }

    return 0;
}

以上是关于HDU4203 Doubloon Game博弈+规律的主要内容,如果未能解决你的问题,请参考以下文章

HDU 1525 Euclid's Game (博弈)

HDU 1079 Calendar Game(规律博弈)

HDU5014 Game(尼姆博弈)

HDU 1846 Brave Game (博弈水题)

HDU 3389 Game (阶梯博弈)

hdu2174 kiki's game 博弈