【poj2234】 Matches Game

http://poj.org/problem?id=2234 (题目链接)

题意

  经典取火柴游戏

Solution

  裸的Nim游戏,也就是取石子。

  整个游戏的sg值为每一堆火柴(子游戏)的异或和。

代码

// poj2960
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<map>
#define inf 2147483640
#define LL long long
#define free(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);
using namespace std;
inline LL getint() {
    LL x=0,f=1;char ch=getchar();
    while (ch>'9' || ch<'0') {if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return x*f;
}



int main() {
    int n;
    while (scanf("%d",&n)!=EOF) {
        int ans=0;
        for (int i=1;i<=n;i++) {
            int x;
            scanf("%d",&x);
            ans^=x;
        }
        if (ans) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

  

posted @ 2016-09-27 22:29  MashiroSky  阅读(292)  评论(0编辑  收藏  举报