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 }
  • 相关阅读:
    散户如何战胜专业投资机构
    机器学习总结
    进程线程及堆栈关系的总结
    线程堆栈是如何增长的
    Ubuntu下CodeBlocks控制台程序中文显示乱码解决问题
    jdk 安装
    python文件运行报错:Error: Please select a valid Python interpreter
    python 解释器安装
    allure在pycharm下运行出现以下乱码的提示 解决方案
    pytest 测试环境框架搭建
  • 原文地址:https://www.cnblogs.com/Y-E-T-I/p/8387234.html
Copyright © 2011-2022 走看看