由于异或运算满足结合律,我们把当前状态的SG函数定义为 它所能切割成的所有纸片对的两两异或和之外的最小非负整数。

#include<cstdio>
#include<set>
#include<cstring>
using namespace std;
int n,m,SG[201][201];
int sg(int x,int y)
{
	if(SG[x][y]!=-1) return SG[x][y];
	set<int>S;
	for(int i=2;i<=x-2;++i) S.insert(sg(i,y)^sg(x-i,y));
	for(int i=2;i<=y-2;++i) S.insert(sg(x,i)^sg(x,y-i));
	for(int i=0;;++i) if(S.find(i)==S.end()) return SG[x][y]=i;
}
int main()
{
	memset(SG,-1,sizeof(SG));
	while(scanf("%d%d",&n,&m)!=EOF)
	  puts(sg(n,m)?"WIN":"LOSE");
}

相关文章:

  • 2021-08-05
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
  • 2021-10-24
猜你喜欢
  • 2021-07-16
  • 2021-07-14
  • 2021-08-17
  • 2021-09-17
  • 2021-06-17
  • 2021-07-01
相关资源
相似解决方案