HDU 3951 Coin Game (博弈)

来源:互联网 发布:域名注册godaddy 编辑:程序博客网 时间:2024/05/29 18:22

题意:

t个样例,每次给你n和k,n是一共有的硬币数,k是你每次最多取得硬币数。
注意:你如果想要取5个硬币(假设能取),那么你必须保证这些硬币是连续的,就是说这些硬币之间不能有空位。

思路:

跟之前的一道题思路差不多。
http://blog.csdn.net/wing_wuchen/article/details/52122914
当k为1时,直接判断奇偶来决定结果。
当k不为1时,如果先手不能一次取完,那么总有后手可以取先手的中心对称的位置来获胜。因为中心对称可以保证不连续的性质也是中心对称。

AC代码:

#include <iostream>#include <cstdio>using namespace std;int main(){    int t;    cin>>t;    int n,k;    int cas = 0;    while(t--){        cas++;        scanf("%d%d",&n,&k);        printf("Case %d: ",cas);        if(k == 1){            if(n&1)                puts("first");            else                puts("second");        }        else{            if(n <= k)                puts("first");            else                puts("second");        }    }    return 0;}
0 0