zoukankan      html  css  js  c++  java
  • [bzoj1022/poj3480]小约翰的游戏John_博弈论

    小约翰的游戏John

    题目大意:Nim游戏。区别在于取走最后一颗石子这输。

    注释:$1le cases le 500$,$1le nle 50$。


    想法:anti-SG游戏Colon定理。

    如果当前SG不为0且存在一个子游戏的SG大于1,则先手必胜。

    如果当前SG为0且不存在一个子游戏的SG大于1,则先手必败。

    这里的SG就是正常的SG。

    直接判断即可。

    最后,附上丑陋的代码... ..

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int main()
    {
    	int cases; cin >> cases ;
    	while(cases--)
    	{
    		int ans=0; bool flag=false;
    		int n; scanf("%d",&n); for(int i=1;i<=n;i++)
    		{
    			int x; scanf("%d",&x);
    			if(x>1) flag=true;
    			ans^=x;
    		}
    		printf("%s
    ",((ans&&flag)||(!ans&&!flag))?"John":"Brother");
    	}
    	return 0;
    }
    

    小结:博弈论真有趣... ...

  • 相关阅读:
    6.8
    6.7
    6.2
    6.1儿童节
    5.24
    5.22
    5.18
    5.17
    Visual Studio开始一个HelloWorld的enclave程序
    以太坊MPT树的HP(Hex-Prefix)编码
  • 原文地址:https://www.cnblogs.com/ShuraK/p/9614606.html
Copyright © 2011-2022 走看看