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 }
  • 相关阅读:
    bug、兼容性、适配问题
    关于daterangepicker取消默认值的设置
    重构-改善既有代码设计
    iphoneX 适配
    汇编语言(2)程序表示
    汇编语言(1)基础理论
    css 边框颜色渐变的半圆
    横向时间轴(进度条)
    pdf中内嵌字体问题
    jabRef里引用的相邻同名作者变横线
  • 原文地址:https://www.cnblogs.com/Y-E-T-I/p/8387234.html
Copyright © 2011-2022 走看看