zoukankan      html  css  js  c++  java
  • hdu 4155 The Game of 31 博弈论

    给出序列,在剩下的卡中选择,谁先拿到大于31的输,搜一下就可以了!

    代码如下:

     1 #include<cstdio>
     2 #include<cstring>
     3 char str[25];
     4 int a[7],sum;
     5 bool dfs(int m)
     6 {
     7     if(m>=31) return 0;
     8     for(int i=1;i<=6;i++){
     9         if(a[i]&&m+i<=31){
    10             a[i]--;
    11             if(!dfs(m+i)){
    12                 a[i]++;
    13                 return 1;
    14             }
    15             a[i]++;
    16         }
    17     }
    18     return 0;
    19 }
    20 int main()
    21 {
    22     while(scanf("%s",str)!=EOF){
    23         int l=strlen(str);
    24         for(int i=1;i<=6;i++) a[i]=4;
    25         sum=0;
    26         for(int i=0;i<l;i++){
    27             sum+=str[i]-'0';
    28             a[str[i]-'0']--;
    29         }
    30         printf("%s ",str);
    31         if(sum>=31){
    32             if(l&1) puts("A");
    33             else puts("B");
    34             continue;
    35         }
    36         if(dfs(sum)){
    37             if(l&1) puts("B");
    38             else puts("A");
    39         }
    40         else{
    41             if(l&1) puts("A");
    42             else puts("B");
    43         }
    44     }
    45     return 0;
    46 }
    View Code
  • 相关阅读:
    SVN 图标消失
    svn 图标不显示
    wamp 局域网访问
    php程序 注册机制
    ThinkphpCMF笔记
    thinkphp缓存
    wampserver与 thinkphp 安装
    js function集合
    php function集合
    php sleep
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3300885.html
Copyright © 2011-2022 走看看