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
  • 相关阅读:
    感知机学习笔记
    NOIP 模拟19
    NOIP 模拟17
    NOIP模拟14-16
    「动态规划」-数位dp专题
    8.5 NOIP 模拟测试 13
    8.3 NOIP 模拟12题解
    8.3 NOIP CE反思
    「分治」-cdq分治
    8.1 NOIP模拟11
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3300885.html
Copyright © 2011-2022 走看看