博弈论模型(巴什博弈)

xiaoxiao2021-02-28  122

巴什博奕:只有一堆n个物品,两个人轮流从中取物,规定每次最少取一个,最多取m个,最后取光者为胜。 那么如果我们要报n个数,每次最少报一个,最多报m个,我们可以找到这么一个整数k和r,使n=k*(m+1)+r,代入上面的例子我们就可以知道,如果r=0,那么先手必败;否则,先手必胜。

#include <iostream> using namespace std; int main() { int n,m; while(cin>>n>>m) if(n%(m+1)==0) cout<<"后手必胜"<<endl; else cout<<"先手必胜"<<endl; return 0; }
转载请注明原文地址: https://www.6miu.com/read-39714.html

最新回复(0)