zoukankan      html  css  js  c++  java
  • Digital Deletions HDU

    Digital deletions is a two-player game. The rule of the game is as following. 

    Begin by writing down a string of digits (numbers) that's as long or as short as you like. The digits can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and appear in any combinations that you like. You don't have to use them all. Here is an example: 



    On a turn a player may either: 
    Change any one of the digits to a value less than the number that it is. (No negative numbers are allowed.) For example, you could change a 5 into a 4, 3, 2, 1, or 0. 
    Erase a zero and all the digits to the right of it. 


    The player who removes the last digit wins. 


    The game that begins with the string of numbers above could proceed like this: 



    Now, given a initial string, try to determine can the first player win if the two players play optimally both. 

    InputThe input consists of several test cases. For each case, there is a string in one line. 

    The length of string will be in the range of [1,6]. The string contains only digit characters. 

    Proceed to the end of file. 
    OutputOutput Yes in a line if the first player can win the game, otherwise output No. 
    Sample Input

    0
    00
    1
    20

    Sample Output

    Yes
    Yes
    No
    No

    思路:必败态可以转移到必胜态,sg搜一下。
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    const int MAX=1000000;
    int sg[MAX];
    int getlength(int n){
        if(n/100000) return 6;
        if(n/10000) return 5;
        if(n/1000) return 4;
        if(n/100) return 3;
        if(n/10) return 2;
        return 1;
    } 
    void extend(int n){
        int len=getlength(n);
        for(int i=len;i>0;i--){
            int m=n;
            int x=1;
            for(int j=1;j<i;j++) x*=10;
            int index=(n%(x*10))/x;
            for(int j=index;j<9;j++){
                m+=x;
                sg[m]=1;
            }
        }    
        if(len<6){
            int m=n;
            int x=1;
            for(int i=len;i<6;i++)
            {
                m*=10;
                for(int i=0;i<x;i++)
                    sg[m+i]=1;
                x*=10;
            }    
        }
    }
    void fun(){
        memset(sg,0,sizeof(sg));
        sg[0]=1;
        for(int i=1;i<MAX;i++)
            if(!sg[i])
                extend(i);
    }
    int main(){
        char str[8];
        int n;
        fun();
        while(scanf("%s",&str)!=EOF)
        {
            if(str[0]=='0')  //第一个数字是0,则前者必胜 
            {
                printf("Yes
    ");
                continue;
            }    
            int len=strlen(str);//第一个数字非0,再转化成整型数 
            n=0;
            for(int i=0;i<len;i++)
            {
                n*=10;
                n+=str[i]-'0';
            }        
            if(sg[n]) printf("Yes
    ");
            else  printf("No
    ");
        }    
        return 0;
    }
    View Code
  • 相关阅读:
    句法分析树标注集
    LaTeX入门教程(二)
    LaTeX入门教程(一)
    汉语词性对照表[北大标准/中科院标准]
    Python版C语言词法分析器
    QT5.4 计算器程序 打包&发布,解决dll的最新解决方案
    解决Android SDK Manager更新(一个更新Host的程序的原理实现和源码)
    增加个人博客地址,欢迎访问
    Matlab R2012b启动出现License Manager Error -15
    C++中二维数组的动态创建与处理
  • 原文地址:https://www.cnblogs.com/astonc/p/10026409.html
Copyright © 2011-2022 走看看