A - Digital Deletions HDU - 1404

It's a bit far-fetched to use sg. Personally, I think what I know about SG is related to the game of Nim.

The problem is just the result of violence, save it.

This question is divided into two situations.
The first case is that the first place in the series is 0, so long as the first place is 0, it must be the winning point.

The second case is that the first one is not zero, so this series of numbers can be regarded as a number.
	1 is bound to be a failure point.
	Then, from violence to 999999.
	If this state is a failure, then you will find violence in his predecessor state (that is, the state of operation can reach that state). As we all know, as long as one step can reach the goal of defeat, it must be a winning point.



#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 1e6;
int sg[maxn];

char str[8];

int getlen(int x)
{
    int len = 0;
    while(x)
    {
        len++;
        x/=10;
    }
    return len;
}
void Sg()
{
    memset(sg, 0, sizeof(sg));
    sg[0]= 1;
    sg[1] = 0;
    for(int i = 1;i < maxn;i++)
    {
        if(sg[i])continue;

        int l = getlen(i);

        int base = 1;
        for(int j = 0;j < l;j++)// One step bigger than him can achieve his winning point.
        {
            int num = i;
            num/=base;
            int b = num%10;


            for(int k = 1;k +b <= 9;k++)
            {
               sg[i+ base*k] = 1;
            }
            base *=10;
        }

        int num1 = i;
        base = 1;
        for(;l < 6;l++)
        {
            num1*=10;
            for(int k= 0;k < base;k++)
            {
                sg[num1+k] = 1;
            }
            base*=10;
        }


    }
}

int main()
{
    Sg();
    while(~scanf("%s", str))
    {
        if(str[0] == '0')printf("Yes\n");
        else
        {
            int num = 0;
            for(int i = 0;str[i]!= '\0';i++)
                num =num*10+str[i]-'0';
            if(sg[num])printf("Yes\n");
            else printf("No\n");
        }
    }
    return 0;
}

Posted by RockRunner on Sun, 06 Oct 2019 05:45:58 -0700