题目链接: uva 1482 - Playing With Stones
题目大意:n堆石子,给定每堆石子的个数,两个人分别从操作,每次可以从一堆中取走至少一个石子,但是不能超过一半。如果不能操作则视为失败。
解题思路:对于每一堆式子来说,可以看作一个Nim游戏,但是SG(x)并不等于x,因为每次取石子不能超过一半,所以对于偶数SG(x)=x/2,对于奇数SG(x)=SG(x/2).
所以去Nim和即可。
#include
#include
#include
using namespace std; typedef long long ll; ll SG (ll x) { return x&1 ? SG(x>>1) : x>>1; } int main () { int cas, n; scanf("%d", &cas); while (cas--) { ll m, v = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", &m); v ^= SG(m); } printf("%s\n", v ? "YES" : "NO"); } return 0; }