题目:
http://acm.hdu.edu.cn/showproblem.php?pid=2509
题意:
有m个苹果分成n组,两个人从某一组轮流取苹果,每次可以取连续的一段苹果,最后无苹果可取的人获胜,求先手是否必胜
思路:
典型的Anti-SG游戏
Anti−SG:
- Anti−SG 游戏规定,决策集合为空的游戏者赢。
- Anti−SG 其他规则与 SG 游戏相同。
SJ定理:
对于任意一个
Anti−SG
游戏,如果我们规定当局面中所有的单一游戏的
SG
值为
0
时,游戏结束,则先手必胜当且仅当:
- 游戏的
SG 函 数不为 0 且游戏中某个单一游戏的 SG 函数大于 1 ; - 游戏的
SG 函数 为 0 且游戏中没有单一游戏的SG 函数大于 1 <script type="math/tex" id="MathJax-Element-16">1</script>。#include <bits/stdc++.h> using namespace std; const int N = 100 + 10; int main() { int n; while(~ scanf("%d", &n)) { int ans = 0, a; bool flag = true; for(int i = 1; i <= n; i++) { scanf("%d", &a); if(a > 1) flag = false; ans ^= a; } if(flag) puts(ans ? "No" : "Yes"); else puts(ans ? "Yes" : "No"); } return 0; }