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

    这是一道简单的博弈题。刚开始我用建表的方法来做,代码如下:

    //Time 31ms, Memory 15920K
    
    #include<iostream>
    #include<cstring>
    using namespace std;
    int a[2001][2001];
    int main()
    {
        int i,j,n,m,t;
        memset(a,0,sizeof(a));
        for(i=0;i<=2000;i++) for(j=0;j<=2000;j++)
        {
            t=1;
            if(i) t*=a[i-1][j];
            if(j) t*=a[i][j-1];
            if(i && j) t*=a[i-1][j-1];
            a[i][j]=!t;
        }
        while(cin>>n>>m && (n || m))
        {
            if(a[n-1][m-1]) cout<<"Wonderful!"<<endl;
            else cout<<"What a pity!"<<endl;
        }
        return 0;
    }
    

    我提交后,Memory Limit Exceeded!于是我在建表的基础上让其输出前100个,看看有没有规律。诶,还真的发现了规律,但我不知道为什么会有这种规律。代码如下:

    //Time 15ms, Memory 232K
    #include<stdio.h>
    int main()
    {
        int n,m;
        while(scanf("%d%d",&n,&m)==2 && (n || m))
        {
            if(n%2 && m%2) printf("What a pity!\n");
            else printf("Wonderful!\n");
        }
        return 0;
    }
    


  • 相关阅读:
    做汉堡(续)
    做汉堡
    <构建之法>3-5章感想
    《构建之法》1-2章感想
    四则运算界面练习
    快速排序
    冒泡算法(思路1)
    希尔排序
    KMP算法
    1、基础算法题
  • 原文地址:https://www.cnblogs.com/java20130726/p/3218206.html
Copyright © 2011-2022 走看看