Be the Winner(博弈论--anti-Nim--反尼姆博弈)

Be the Winner(博弈论--anti-Nim--反尼姆博弈)

judge:hduoj 2509
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
source:ECJTU 2008 Autumn Contest

描述

Let’s consider m apples divided into n groups. Each group contains no more than 100 apples, arranged in a line. You can take any number of consecutive apples at one time.
judge:hduoj 2509

Input

judge:hduoj 2509

Output

judge:hduoj 2509

Sample Input

2
2 2
1
3

Sample Output

No
Yes

题意

给你N堆石子,两人交替取石子,每次只能取一堆中的石子且能去任意个,但不能不取。**最后取得那个人输!**问你先手能否有必胜得把握。

典型的反尼姆博弈问题。在这里引用大佬得结论和证明:
在这里插入图片描述
在这里插入图片描述
证明链接:《组合游戏略述——浅谈SG游戏的若干拓展及变形》石家庄二中贾志豪

代码
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cstring>
#include <cmath>
#include <limits.h>
#include <map>
#define maxn 100005
#define eps 0.000000001
using namespace std;
typedef long long ll;


int main(){
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);

    int n;
    while(cin >> n){
        int ans = 0, f = 1;
        while(n--){
            int x;
            cin >> x;
            ans ^= x;
            if(x > 1) f = 0;
        }
        printf("%s\n", (f && !ans)||(!f && ans) ? "Yes" : "No");
    }
    return 0;
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值