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;
    }
    


  • 相关阅读:
    codeforces 938 C. Constructing Tests
    codeforces 981 C.Useful Decomposition
    Wannafly 挑战赛16 A 取石子
    codeforces 873 D. Merge Sort(分治)
    lightoj 1158
    lightoj 1226
    lightoj 1382
    lightoj 1283
    hdu 5445 Food Problem (多重背包)
    light 1205
  • 原文地址:https://www.cnblogs.com/java20130726/p/3218206.html
Copyright © 2011-2022 走看看