zoukankan      html  css  js  c++  java
  • 1404-Digital Deletions

    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:

    1404-Digital <wbr>Deletions


    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:

    1404-Digital <wbr>Deletions


    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
    00 
    20
    Sample Output
    Yes 
    Yes 
    No 
    No
    组合博弈,暴力打表
    #include
    #include
    int len;
    int win[1000000];
    char s[10];
    int solve(int num)
    {
        int i,j,k,k2=num,p=1;
        while(k2)
        {

            k=num/p;
            if(k==0)
            {
                if(!win[num/p/10])
                  return 1;
            }
            else
            {
                for(i=1;i<=k;i++)
                {
                    if(!win[num-i*p] &&  !(i==k && k2/10==0))
                     return 1;
                }

            }
            k2/=10;
            p*=10;
        }
        return 0;
    }
    int main()
    {
        int i,j,k;
        win[0]=1;
        for(i=1;i<1000000;i++)
           if(solve(i))
             win[i]=1;
        while(~scanf("%s",s+1))
        {
            if(s[1]=='0')
            {
                printf("Yes ");
                continue;
            }
            len=strlen(s+1);
            k=0;
            for(i=1;i<=len;i++)
               k=k*10+s[i]-'0';
            if(win[k])
              printf("Yes ");
            else
              printf("No ");
        }
    }

  • 相关阅读:
    929. 独特的电子邮件地址
    [工具.tcp]测试TCP通讯的网络延迟
    [技巧.Dotnet]轻松实现“强制.net程序以管理员身份运行”。
    [问题记录.VisualStudio]VS2013无法新增和打开项目
    [问题记录.VisualStudio]TFS项目映射问题解决
    [问题记录.dotnet]取网卡信息报错"找不到"-WMI
    模型驱动的数学原理
    剑指OFFER 旋转数组的最小数字
    剑指OFFER 用两个栈实现队列
    剑指OFFER 按之字形顺序打印二叉树
  • 原文地址:https://www.cnblogs.com/kuroko-ghh/p/9363388.html
Copyright © 2011-2022 走看看