hdoj 1846 Brave Game (巴什博弈)

传送门

最简单的博弈论问题
这种问题简单来说,就是两个人在 (n) 个石子中,每次只能取 (1...m) 个石子,最先取完的人胜利,给定 (n,m) 求谁能胜利
比较容易发现,当 (n=m+1) 时,不管先手怎么取,后手都能取完,所以后手必胜
把这种局面扩展一下,如果 (n\% (m+1)=0) 的话,后手也必胜,因为他可以通过每次和先手一起取 (m+1) 个来控制局面,直到取完
那么如果 (n\% (m+1)=s (0<sleq m)),那么先手可以先取 (s) 个,然后发现先手控制了 (n\% (m+1)=0) 的局面,先手必胜了
那么这个题就完成了

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int T,n,m;

int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&m);
        int temp=n%(m+1);
        if(temp>=1) printf("first
");
        else printf("second
");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/BakaCirno/p/11820360.html