标签:ref was span std 交换 异或 nim cstring eof
题解:
首先,由$SG$定理得$SG(x,y)=mex(SG(x‘,y)^SG(x,y‘)^SG(x‘,y‘))(x‘<x,y‘<y)$
这里的$SG(x,y)$叫$Nim$积。
$Nim$积满足交换律、结合律以及对$Nim$和(异或)的分配律。
代码:
#include<cstdio> #include<cstring> int T,n; int mp[1050][1050]; int nim_mul(int x,int y) { if(x<y)x^=y^=x^=y; if(x<=1000&&~mp[x][y])return mp[x][y]; if(!y)return mp[x][y]=0; if(x==1)return mp[x][y]=1; int t = 2; while(t*t<=x)t=t*t; int c1 = nim_mul(x/t,y/t); int c2 = nim_mul(x/t,y%t)^nim_mul(x%t,y/t); int c3 = nim_mul(x%t,y%t); int ret = (c1^c2)*t^c3^nim_mul(t/2,c1); if(x<=1000)mp[x][y]=ret; return ret; } int main() { scanf("%d",&T); memset(mp,-1,sizeof(mp)); while(T--) { int ans = 0; scanf("%d",&n); while(n--) { int x,y; scanf("%d%d",&x,&y); ans^=nim_mul(x,y); } puts(ans?"Have a try, lxhgww.":"Don‘t waste your time."); } return 0; }
标签:ref was span std 交换 异或 nim cstring eof
原文地址:https://www.cnblogs.com/LiGuanlin1124/p/10351723.html