zoukankan      html  css  js  c++  java
  • HDU_2147——组合博弈,转换为P/N图,然后找规律

    Problem Description
    Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she just playes the checkerboard game.The size of the chesserboard is n*m.First of all, a coin is placed in the top right corner(1,m). Each time one people can move the coin into the left, the underneath or the left-underneath blank space.The person who can't make a move will lose the game. kiki plays it with ZZ.The game always starts with kiki. If both play perfectly, who will win the game?
     
    Input
    Input contains multiple test cases. Each line contains two integer n, m (0<n,m<=2000). The input is terminated when n=0 and m=0.
     
    Output
    If kiki wins the game printf "Wonderful!", else "What a pity!".
     
    Sample Input
    5 3 5 4 6 6 0 0
     
    Sample Output
    What a pity! Wonderful! Wonderful!
    #include <iostream>
    using namespace std;
    
    int a[2001][2001];
    void init(void)
    {
        a[1][1] = 1;    //必败点
        for(int i = 2; i < 2001; i++)   //第一行与第一列
        {
            if(a[1][i-1])
                a[1][i] = 0;    //一步能进入必败点标记为必胜点
            else
                a[1][i] = 1;    //不能标记为必败点
    
            if(a[i-1][1])
                a[i][1] = 0;    //一步能进入必败点标记为必胜点
            else
                a[i][1] = 1;    //不能标记为必败点
        }
        for(int i = 2; i < 2001; i++)   //中间的位置
        {
            for(int j = 2; j < 2001; j++)
            {
                if(a[i][j-1] || a[i-1][j] || a[i-1][j-1])
                    a[i][j] = 0;    //一步能进入必败点标记为必胜点
                else
                    a[i][j] = 1;    //不能标记为必败点
            }
        }
    }
    
    int main()
    {
        /*
        画P/N图得出当n,m为奇数时kiki必败
        init();
        for(int i = 1; i < 50; i++)
        {
            for(int j = 1; j < 50; j++)
            {
                if(a[i][j])
                {
                    cout << i%2 << " " << j%2 << endl;
                }
            }
        }
        */
        int n, m;
        while(cin >> n >> m && (n || m))
        {
            if(n%2 && m%2)
                cout << "What a pity!" << endl;
            else
                cout << "Wonderful!" << endl;
        }
    
        return 0;
    }
  • 相关阅读:
    php简单的server登陆验证
    CentOS更新php(PHP 5.2+ is required问题)
    CentOS 5.5 x86_64下安装oci8与pdo_oci扩展
    httpd.conf详解
    Thinkphp中去除URL里的index.php
    Oracle使用虚拟表dual一次插入多条记录【摘录】
    【问题】apache目录403错误
    mysql中存储引擎MyISAM与InnoDB的一些区别
    从开辟蓝海到保卫蓝海(三)
    答MM问:经济泡沫破了不更好吗?
  • 原文地址:https://www.cnblogs.com/pingge/p/3388075.html
Copyright © 2011-2022 走看看