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;
}