zoukankan      html  css  js  c++  java
  • POJ 2234 Matches Game 尼姆博弈

    题目大意:尼姆博弈,判断是否先手必胜。

    题目思路:

    尼姆博弈:有n堆各a[]个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取一个,多者不限,最后取光者得胜。

    获胜规则:ans=(a[1]^a[2] ……^a[n]),若ans==0则后手必胜,否则先手必胜.

    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<vector>
    #include<stdio.h>
    #include<stdlib.h>
    #include<queue>
    #include<math.h>
    #include<map>
    #define INF 0x3f3f3f3f
    #define MAX 1005
    #define Temp 1000000000
    
    using namespace std;
    
    int main()
    {
        int n,m,ans;
        while(scanf("%d",&n)!=EOF)
        {
            ans=0;
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&m);
                ans^=m;
            }
            if(ans > 0)
                printf("Yes
    ");
            else
                printf("No
    ");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    C#
    C#
    C#
    python——socket网络编程
    Python——面向对象
    Python——函数
    Python——列表深浅拷贝
    Python——文件操作
    多级菜单(增强版)
    Python 编码机制
  • 原文地址:https://www.cnblogs.com/alan-W/p/5960735.html
Copyright © 2011-2022 走看看