可以发现这个游戏其实是n2n2个独立的游戏,只要分别求出这些独立游戏的SGSG函数,把它们异或起来之后,如果为00则先手败,否则先手胜。
设表示左边一堆aa个石子,右边一堆个石子,这种状态下的SGSG值。但是aa和是2×1092×109级别的。
找规律大法好!
aa和都是奇数时,SG(a,b)=0SG(a,b)=0
否则SG(a,b)=SG(⌈a2⌉⌈b2⌉)+1SG(a,b)=SG(⌈a2⌉⌈b2⌉)+1
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
inline int read() {
int res = 0; bool bo = 0; char c;
while (((c = getchar()) < '0' || c > '9') && c != '-');
if (c == '-') bo = 1; else res = c - 48;
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + (c - 48);
return bo ? ~res + 1 : res;
}
const int N = 2e4 + 5;
int n, a[N];
int SG(int x, int y) {
if ((x & 1) && (y & 1)) return 0; if (x & 1) x++; if (y & 1) y++;
return SG(x >> 1, y >> 1) + 1;
}
void work() {
int i, ans = 0; n = read(); for (i = 1; i <= n; i++) a[i] = read();
for (i = 1; i <= n; i += 2) ans ^= SG(a[i], a[i + 1]);
puts(ans != 0 ? "YES" : "NO");
}
int main() {
int T = read(); while (T--) work();
return 0;
}