zoukankan      html  css  js  c++  java
  • 【博弈论】【SG函数】poj2311 Cutting Game

    由于异或运算满足结合律,我们把当前状态的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");
    }
  • 相关阅读:
    简单状态机
    c语言状态机
    存储公司
    正确跑步
    好好做自己能做的
    I2C学习
    es6 generator函数
    es6 for of 循环
    es6 proxy代理
    es6 Symbol类型
  • 原文地址:https://www.cnblogs.com/autsky-jadek/p/4337011.html
Copyright © 2011-2022 走看看