NYOJ 135 & 585 (博弈问题)

来源:互联网 发布:暴风影音windows版 编辑:程序博客网 时间:2024/04/28 01:57
#include <stdio.h>#if 1int main()//游戏类型 : B    T135{int t;scanf("%d",&t);while(t--){int N, temp = 0;scanf("%d",&N);while(N--){int m, n;scanf("%d%d", &m, &n);temp ^= m % (n + 1);//f(x) = x % (n + 1), x: 每堆石子数, n: 每堆最多取的数目;   f(x) 的二进制异或运算, 同为0, 不同为1}if(temp != 0)//先行者胜printf("Win\n");elseprintf("Lose\n");}return 0;}#elseint main()//游戏类型 : AT585{int t;scanf("%d",&t);while(t--){int m, temp = 0;scanf("%d",&m);while(m--){int n;scanf("%d", &n);//f(x) = x ,   x: 每堆石子数temp ^= n;//f(x) 的二进制异或运算, 同为0, 不同为1}if(temp != 0)//先行者胜printf("PIAOYI\n");elseprintf("HRDV\n");}return 0;}#endif