zoukankan      html  css  js  c++  java
  • HDU 2147 kiki's game

    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!
    这东西好像叫巴什博弈
    跟上一题一样,最后(n,m)肯定是P
    然后一个一个推出(1,1)是N还是P
    但是每次都2000×2000可能会超
    所以把棋盘反转(n,m)变成了(1,1)
    于是直接判断(1,1)~(n,m)
    起点就变成了(n,m),终点为(1,1)可以O(1)查询
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 using namespace std;
     7 bool ans[2001][2001];
     8 int n,m;
     9 int main()
    10 {int i,j;
    11   ans[1][1]=0;
    12   for (i=2;i<=2000;i++)
    13     if (ans[1][i-1]==1)
    14       ans[1][i]=0;
    15     else ans[1][i]=1;
    16   for (i=2;i<=2000;i++)
    17     if (ans[i-1][1]==1)
    18       ans[i][1]=0;
    19     else ans[i][1]=1;
    20   for (i=2;i<=2000;i++)
    21     {
    22       for (j=2;j<=2000;j++)
    23     {
    24       if (ans[i-1][j]==0||ans[i][j-1]==0||ans[i-1][j-1]==0)
    25         ans[i][j]=1;
    26       else ans[i][j]=0;
    27     }
    28     }
    29   while (cin>>n>>m&&n&&m)
    30     {
    31       if (ans[n][m]==1)
    32     printf("Wonderful!
    ");
    33       else printf("What a pity!
    ");
    34     }
    35 }
  • 相关阅读:
    cisco telnet(转载)
    华为bfd配置步骤
    cisco ssh实验--附带配置脚本-2019.11.19
    远程设备管理opendx平台搭建-server,agent以及front实际搭建
    远程设备管理opendx平台搭建-appium和adb的安装
    华为交换机sflow配置
    华为交换机netstream配置
    centos6虚拟机复制后修改网卡
    docker基本操作
    esxi 6 添加硬盘、网卡
  • 原文地址:https://www.cnblogs.com/Y-E-T-I/p/8387234.html
Copyright © 2011-2022 走看看