下面几张图是引入,截自2009年论文《从“k倍动态减法游戏”出发探究一类组合游戏问题》
翻转四个格子。设 S G ( x , y ) = x ⊗ y SG(x,y)=x\otimes y SG(x,y)=x⊗y
x ⊗ y = m e x { ( a ⊗ y ) ⊕ ( x ⊗ b ) ⊕ ( a ⊗ b ) ∣ 0 ≤ a < x , 0 ≤ b < y } x\otimes y=mex\{(a\otimes y)\oplus(x\otimes b)\oplus(a\otimes b)~|~0\le a<x,0\le b<y\} x⊗y=mex{(a⊗y)⊕(x⊗b)⊕(a⊗b) ∣ 0≤a<x,0≤b<y}
经过一些不知道怎么推的数学推导,可以得到一些运算性质:
(1) 交换律: x ⊗ y = y ⊗ x x\otimes y=y\otimes x x⊗y=y⊗x
(2) 结合律: ( x ⊗ y ) ⊗ z = x ⊗ ( y ⊗ z ) (x\otimes y)\otimes z=x\otimes (y\otimes z) (x⊗y)⊗z=x⊗(y⊗z)
(3) 对异或的分配律: ( x ⊕ y ) ⊗ z = ( x ⊗ z ) ⊕ ( y ⊗ z ) (x\oplus y)\otimes z=(x\otimes z)\oplus (y\otimes z) (x⊕y)⊗z=(x⊗z)⊕(y⊗z)
(4) 单位元: x ⊗ 1 = 1 ⊗ x x\otimes 1=1\otimes x x⊗1=1⊗x
对于 x , y < 2 2 n x,y<2^{2^n} x,y<22n:
(1) x ⊗ 2 2 p = x ∗ 2 2 p x\otimes 2^{2^p}=x*2^{2^p} x⊗22p=x∗22p
(2) x ⊗ y < 2 2 n x\otimes y<2^{2^n} x⊗y<22n
(3) 2 2 n ⊗ 2 2 n = 3 2 ∗ 2 2 n 2^{2^n}\otimes 2^{2^n}=\frac 32 *2^{2^n} 22n⊗22n=23∗22n
(4) 逆元: x ⊗ x 2 2 n − 2 = x 2 2 n − 1 = 1 x\otimes x^{2^{2^{n}}-2}=x^{2^{2^n}-1}=1 x⊗x22n−2=x22n−1=1
运算举例:
运算实现:yamf 的 blog
用类似分治乘法计算,复杂度 O ( 4 log log x ) O(4^{\log\log x}) O(4loglogx)
应用:20200729模拟赛 划愤
Code:
#include<bits/stdc++.h>
#define maxn 155
using namespace std;
typedef unsigned long long ULL;
int n;
ULL A[maxn][maxn],nim[256][256];
ULL Nim_mul(ULL x,ULL y,int p=32){
if(x<=1||y<=1) return x*y;
if((x|y)<256&&nim[x][y]) return nim[x][y];
ULL a=x>>p, b=x&(1ull<<p)-1, c=y>>p, d=y&(1ull<<p)-1;
ULL bd=Nim_mul(b,d,p>>1), ac=Nim_mul(Nim_mul(a,c,p>>1),1ull<<p>>1,p>>1);
ULL ret=ac^bd^((Nim_mul(a^b,c^d,p>>1)^bd)<<p);
if((x|y)<256) nim[x][y]=nim[y][x]=ret;
return ret;
}
ULL Pow(ULL a,ULL b){ULL s=1;for(;b;b>>=1,a=Nim_mul(a,a)) b&1&&(s=Nim_mul(s,a));return s;}
ULL Inv(ULL x){return Pow(x,ULL(-2));}
bool Gauss(){
for(int i=1;i<=n;i++){
if(!A[i][i]) for(int j=i+1;j<=n;j++) if(A[j][i]) {swap(A[i],A[j]);break;}
if(!A[i][i]) return 0;
ULL inv = Inv(A[i][i]);
for(int j=i+1;j<=n;j++) if(A[j][i]){
ULL t = Nim_mul(A[j][i],inv);
for(int k=i;k<=n;k++) A[j][k]^=Nim_mul(A[i][k],t);
}
}
return 1;
}
int main()
{
freopen("sui.in","r",stdin);
freopen("sui.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%llu",&A[i][j]);
puts(Gauss()?"xiaoDyingle":"xiaoDwandanle");
}