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!

    【题目链接】:http://acm.hdu.edu.cn/submit.php?pid=2147

    【题解】

    这题如果直接用模拟,n*m从必败往必胜的方向搞;
    会超时;
    正确做法是
    先找规律;
    手动模拟一下必败到必胜的转换
    这里写图片描述
    (0表示到这个点后必败,1表示必胜);
    (只要(i,j-1),(i+1,j-1),(i+1j,j)这3个点中有一个点的状态为必败态,则i,j点的状态为必胜态,因为我们可以接下来一步走到那个点去,这样对方就面临那个必败态了;)

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%I64d",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    //const int MAXN = x;
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    
    int n,m;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        rei(n);rei(m);
        while (n!=0)
        {
            if (n%2==0 || m%2==0)
                puts("Wonderful!");
            else
                puts("What a pity!");
            rei(n);rei(m);
        }
        return 0;
    }
    
  • 相关阅读:
    B. Pasha and Phone
    GCD(关于容斥原理)
    二分乘法
    Lucky7(容斥原理)
    E. Devu and Flowers
    最大公约数最小公倍数
    leetcode每日刷题计划--day55
    Titanic--kaggle竞赛入门-生存预测
    做题记录--day54
    机器学习上机作业1记录 && 相关知识点复习
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626754.html
Copyright © 2011-2022 走看看