Nim积

下面几张图是引入,截自2009年论文《从“k倍动态减法游戏”出发探究一类组合游戏问题》
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

翻转四个格子。设 S G ( x , y ) = x ⊗ y SG(x,y)=x\otimes y SG(x,y)=xy

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\} xy=mex{(ay)(xb)(ab)  0a<x,0b<y}

经过一些不知道怎么推的数学推导,可以得到一些运算性质:

(1) 交换律: x ⊗ y = y ⊗ x x\otimes y=y\otimes x xy=yx

(2) 结合律: ( x ⊗ y ) ⊗ z = x ⊗ ( y ⊗ z ) (x\otimes y)\otimes z=x\otimes (y\otimes z) (xy)z=x(yz)

(3) 对异或的分配律: ( x ⊕ y ) ⊗ z = ( x ⊗ z ) ⊕ ( y ⊗ z ) (x\oplus y)\otimes z=(x\otimes z)\oplus (y\otimes z) (xy)z=(xz)(yz)

(4) 单位元: x ⊗ 1 = 1 ⊗ x x\otimes 1=1\otimes x x1=1x

对于 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} x22p=x22p

(2) x ⊗ y < 2 2 n x\otimes y<2^{2^n} xy<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} 22n22n=2322n

(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 xx22n2=x22n1=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");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值