zoukankan      html  css  js  c++  java
  • HDU 1404 (博弈) Digital Deletions

    首先如果第一个数字是0的话,那么先手必胜。

    对于一个已知的先手必败状态,凡是能转移到先手必败的状态一定是必胜状态。

    比如1是必败状态,那么2~9可以转移到1,所以是必胜状态。

    10,10*,10**,10***,10****也都可以删除1后面那个0,转移到1,所以也是必胜状态。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cstdlib>
     4 
     5 const int maxn = 999999;
     6 int sg[maxn + 10];
     7 
     8 void init()
     9 {
    10     char s[10], s1[10];
    11     for(int i = 1, j; i <= maxn; i++) if(!sg[i])//先手必败点
    12     {//所有能转移到先手必败的状态都是先手必胜状态
    13         sprintf(s, "%d", i);
    14         int n = strlen(s);
    15         for(j = 0; j < n; j++)
    16         {//每一位都加上1
    17             strcpy(s1, s);
    18             while(++s1[j] <= '9') sg[atoi(s1)] = 1;
    19         }
    20         int m = i, b = 1;
    21         for(int j = n; j < 6; j++)
    22         {//在后面添0
    23             m *= 10;
    24             for(int k = 0; k < b; k++) sg[m + k] = 1;
    25             b *= 10;
    26         }
    27     }
    28 }
    29 
    30 int main()
    31 {
    32     init();
    33     char s[10];
    34     while(scanf("%s", s) == 1)
    35     {
    36         if(s[0] == '0') { puts("Yes"); continue; }
    37         int n = 0, l = strlen(s);
    38         for(int i = 0; i < l; i++) n = n * 10 + s[i] - '0';
    39         printf("%s
    ", sg[n] ? "Yes" : "No");
    40     }
    41 
    42     return 0;
    43 }
    代码君
  • 相关阅读:
    scala的泛型浅析
    spark2.0的10个特性介绍
    spark2.0 DataSet操作的一些问题记录
    scala中ClassOf、asInstenceOf、isInstanceOf三个预定义方法分析
    Java 多线程与并发编程专题
    java nio入门
    MySQL索引优化详解
    shiro学习笔记-Subject#login(token)实现过程
    【转】线程八锁
    ReadWriteLock读写锁
  • 原文地址:https://www.cnblogs.com/AOQNRMGYXLMV/p/4414366.html
Copyright © 2011-2022 走看看