码迷,mamicode.com
首页 > 其他好文 > 详细

(SG) hdu 1404

时间:2015-03-30 20:47:58      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

Digital Deletions

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2130    Accepted Submission(s): 747


Problem Description
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. 
 

 

Input
The 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.
 

 

Output
Output 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
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define maxn 1000000
char str[10];
int sg[maxn],n;
int get(int x)
{
    if(x/100000) return 6;
    if(x/10000) return 5;
    if(x/1000) return 4;
    if(x/100) return 3;
    if(x/10) return 2;
    return 1;
}
void dfs(int x)
{
    int len=get(x);
    for(int i=1;i<=len;i++)
    {
        int m=x;
        int base=1;
        for(int j=1;j<i;j++) base=base*10;
        int temp=(m%(base*10))/base;
        for(int j=temp;j<9;j++)
        {
            m+=base;
            sg[m]=1;
        }
    }
    if(len!=6)
    {
        int m=x;
        int base=1;
        for(int i=len;i<6;i++)
        {
            m=m*10;
            for(int j=0;j<base;j++)
            {
                sg[m+j]=1;
            }
            base=base*10;
        }
    }
}
void fun()
{
    memset(sg,0,sizeof(sg));
    sg[0]=1;
    for(int i=1;i<maxn;i++)
    {
        if(!sg[i])
           dfs(i);
    }
}
int main()
{
    fun();
    while(scanf("%s",str)!=EOF)
    {
        if(str[0]==‘0‘)
        {
            printf("Yes\n");
            continue;
        }
        int len=strlen(str);
        n=0;
        for(int i=0;i<len;i++)
        {
            n=n*10;
            n=n+str[i]-‘0‘;
        }
        if(sg[n]) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

  

(SG) hdu 1404

标签:

原文地址:http://www.cnblogs.com/a972290869/p/4378939.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!