• hdu 2147 SG函数打表(手写也可以) 找规律


    kiki's game

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others)
    Total Submission(s): 4972    Accepted Submission(s): 2908

    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!
     
    Author
    月野兔
     
    Source
     
    Recommend
    威士忌

    题意:

        在一个n*m的棋盘上,从 (1,m),即右上角开始向左下角走。

          下棋者只能往左边(left),左下面(left-underneath),下面(underneath),这三个方格下棋。

    最后不能移动的人算输

    思路:
    手动可以画出必胜态以及必败态的图
    可以很容易 找出规律

    (1) 所有终结点是必败点(P点);

      (2)从任何必胜点(N点)操作,至少有一种方法可以进入必败点(P点);

     (3)无论如何操作,从必败点(P点)都只能进入必胜点(N点).

    由此可知 10*10之内的为   (完全可以手写出来)

    NNNNNNNNNN
    PNPNPNPNPN
    NNNNNNNNNN
    PNPNPNPNPN
    NNNNNNNNNN
    PNPNPNPNPN
    NNNNNNNNNN
    PNPNPNPNPN
    NNNNNNNNNN
    PNPNPNPNPN

    可以看出  NN

                      PN  这样的规律    之后很容易知道怎么做了    

    #include<stdio.h>
    int main()
    {
        int n,m;
        while(scanf("%d%d",&n,&m))
        {
            if(n==0&&m==0)break;
            if(n%2==1&&m%2==1)printf("What a pity!
    ");
            else printf("Wonderful!
    ");
        }
        return 0;
    }

    还可以用SG函数打表找出我们所要的结果NP 图


    #include<stdio.h>
    #include<string.h>
    const int sz=200;
    int SG[sz][sz];
    int dir[3][2]={-1,0,0,1,-1,1};
    int n,m;
    void get_sg()
    {
        int i,j;
        memset(SG,0,sizeof(SG));
          for(i=n;i>=1;i--)
            for(j=1;j<=m;j++)
          {
              if(!SG[i][j])
                for(int k=0;k<3;k++)
                {
                  int xx=i+dir[k][0];
                  int yy=j+dir[k][1];
                   if(xx>=1&&xx<=n&&yy>=1&&yy<=m)
                   {
                    SG[xx][yy]=1;
                   }
                }
          }
    }
    int main()
    {
        int i,j;
    
        while(scanf("%d %d",&n,&m)!=EOF)
        {
            get_sg();
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=m;j++) if(SG[i][j]==1) printf("N"); else printf("P");
                printf("
    ");
            }
            if(SG[1][m]==1)
            {
                printf("Wonderful!
    ");
            }
            else printf("What a pity!
    ");
        }
        return 0;
    }
    
    
    
    



  • 相关阅读:
    C++ 的那些坑 (Day 0)
    LeetCode Search a 2D Matrix II
    最大子序列和问题的解(共4种,层层推进)
    如何编译文件(gcc + nasm)
    os如何处理键盘的所有按键,显示or不显示,显示是如何显示
    汇编操作显存
    diy文件系统上创建文件的流程
    在diy的文件系统上创建文件的流程
    建立文件系统
    快速选择
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3191952.html
Copyright © 2020-2023  润新知