zoukankan      html  css  js  c++  java
  • 【POJ 2311】 Cutting Game

    【题目链接】

                http://poj.org/problem?id=2311

    【算法】

               博弈论——SG函数

    【代码】

               

    #include <algorithm>  
    #include <bitset>  
    #include <cctype>  
    #include <cerrno>  
    #include <clocale>  
    #include <cmath>  
    #include <complex>  
    #include <cstdio>  
    #include <cstdlib>  
    #include <cstring>  
    #include <ctime>  
    #include <deque>  
    #include <exception>  
    #include <fstream>  
    #include <functional>  
    #include <limits>  
    #include <list>  
    #include <map>  
    #include <iomanip>  
    #include <ios>  
    #include <iosfwd>  
    #include <iostream>  
    #include <istream>  
    #include <ostream>  
    #include <queue>  
    #include <set>  
    #include <sstream>  
    #include <stdexcept>  
    #include <streambuf>  
    #include <string>  
    #include <utility>  
    #include <vector>  
    #include <cwchar>  
    #include <cwctype>  
    #include <stack>  
    #include <limits.h>
    using namespace std;
    #define MAXN 210
    
    int n,m;
    int sg[MAXN][MAXN];
    
    inline int getSG(int n,int m)
    {
            int i;
            bool s[1010];
            if (sg[n][m] != -1) return sg[n][m];
            memset(s,false,sizeof(s));
            for (i = 2; i <= n - 2; i++) s[getSG(n-i,m)^getSG(i,m)] = true;
            for (i = 2; i <= m - 2; i++) s[getSG(n,i)^getSG(n,m-i)] = true;
            for (i = 0; ; i++)
            {
                    if (!s[i])
                            return sg[n][m] = i;
            }
    }
    
    int main() 
    {
            
            memset(sg,255,sizeof(sg));
            while (scanf("%d%d",&n,&m) != EOF)
            {
                    printf(getSG(n,m)?"WIN
    ":"LOSE
    ");        
            }
            
            return 0;
        
    }
  • 相关阅读:
    mysql下载与安装
    Observable Flowable Test
    Linux 技巧:让进程在后台可靠运行的几种方法
    CallBack
    Linux内存分析
    Linux安装svn
    百度地图api
    安装Mysql官方的sakila数据库
    yii2 展示静态页面
    yii2 手动安装第三方扩展
  • 原文地址:https://www.cnblogs.com/evenbao/p/9298908.html
Copyright © 2011-2022 走看看