1300 · 巴什博弈

2021/12/15 23:18:16

本文主要是介绍1300 · 巴什博弈,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

class Solution {
public:
    /**
     * @param n: an integer
     * @return: whether you can win the game given the number of stones in the heap
     */
    bool canWinBash(int n) {
        int m=3;

        if(n%(m+1)){
            return true;
        }
        else return false;

        // Write your code here
    }
};

在先取完者胜的巴什博弈中,若n可被m+1整除,则后手方必胜,否则先手方必胜。

其中 n表示物品总数;m表示每次可以拿的最大个数。



这篇关于1300 · 巴什博弈的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程