SG函数模板(洛谷2197nim游戏
#include <iostream> #include <cstdio> #include <queue> #include <algorithm> #include <cmath> #include <cstring> #define inf 2147483647 #define N 10010 #define p(a) putchar(a) #define For(i,a,b) for(int i=a;i<=b;++i) //by war //2019.8.9 using namespace std; int T,n,ans; int f[N],sg[N],a[N]; bool vis[N]; void in(int &x){ int y=1;char c=getchar();x=0; while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();} while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();} x*=y; } void o(int x){ if(x<0){p('-');x=-x;} if(x>9)o(x/10); p(x%10+'0'); } void SG(int n){ memset(sg,0,sizeof(sg)); sort(f+1,f+n+1); For(i,1,n){ memset(vis,0,sizeof(vis)); for(int j=1;j<=n&&f[j]<=i;j++) vis[sg[i-f[j]]]=1; For(j,0,n) if(!vis[j]){ sg[i]=j; break; } } } signed main(){ in(T); For(i,1,1e4) f[i]=i; SG(1e4); while(T--){ in(n); For(i,1,n) in(a[i]); ans=0; For(i,1,n) ans^=sg[a[i]]; if(!ans) puts("No"); else puts("Yes"); } return 0; }