zoukankan      html  css  js  c++  java
  • hdu 4111 Alice and Bob

    组合游戏题;

    组合游戏的规则:

    1.必败态的所有后继都是必胜态;

    2.必胜态最少有一个必败的后继;

    这里的必胜态是f[1][0][0][0];

    其中f[a][b][c][d]表示有a个1,b个2,c个3,d个4是不是一个必胜态;

    可以认为大于3的奇数等同于3,大于4的偶数等同于4.

    然后递归求解;

     1 #include <iostream>
     2 using namespace std;
     3 
     4 bool vis[51][51][51][51];
     5 bool f[51][51][51][51];
     6 int F(int a,int b,int c,int d)
     7 {
     8     if (!vis[a][b][c][d])
     9     {
    10         //单堆减小一个的情况
    11        if (a>=1&&!F(a-1,b,c,d)) f[a][b][c][d]=true;
    12        if (b>=1&&!F(a+1,b-1,c,d)) f[a][b][c][d]=true;
    13        if (c>=1&&!F(a,b+1,c-1,d)) f[a][b][c][d]=true;
    14        if (d>=1&&!F(a,b,c+1,d-1)) f[a][b][c][d]=true;
    15         //两两合并的情况
    16        if (a>=2&&!F(a-2,b+1,c,d)) f[a][b][c][d]=true;
    17        if (b>=2&&!F(a,b-2,c,d+1)) f[a][b][c][d]=true;
    18        if (c>=2&&!F(a,b,c-2,d+1)) f[a][b][c][d]=true;
    19        if (d>=2&&!F(a,b,c,d-2+1)) f[a][b][c][d]=true;
    20 
    21        if (a>=1&&b>=1&&!F(a-1,b-1,c+1,d)) f[a][b][c][d]=true;
    22        if (a>=1&&c>=1&&!F(a-1,b,c-1,d+1)) f[a][b][c][d]=true;
    23        if (a>=1&&d>=1&&!F(a-1,b,c+1,d-1)) f[a][b][c][d]=true;
    24        if (b>=1&&c>=1&&!F(a,b-1,c-1+1,d)) f[a][b][c][d]=true;
    25        if (b>=1&&d>=1&&!F(a,b-1,c,d-1+1)) f[a][b][c][d]=true;
    26        if (c>=1&&d>=1&&!F(a,b,c-1+1,d-1)) f[a][b][c][d]=true;
    27 
    28        vis[a][b][c][d]=true;
    29     }
    30     return f[a][b][c][d];
    31 }
    32 
    33 int main()
    34 {
    35     int t,ca=1;
    36     cin>>t;
    37     f[1][0][0][0]=1;
    38     while(t--)
    39     {
    40         int n,a=0,b=0,c=0,d=0;
    41         cin>>n;
    42         for (int i=0;i<n;i++)
    43         {
    44             int t;
    45             cin>>t;
    46             if (t==1) a++;
    47             else if (t==2) b++;
    48             else if (t%2==1) c++;
    49             else d++;
    50         }
    51         cout<<"Case #"<<ca++<<": "<<(F(a,b,c,d)?"Alice":"Bob")<<endl;
    52     }
    53     return 0;
    54 }
    View Code
  • 相关阅读:
    探索Java8:(二)Function接口的使用
    Vue 动态图片加载路径问题和解决方法
    小工具:使用Python自动生成MD风格链接
    解决Navicat Premium 12 连接oracle数据库出现ORA-28547的问题
    Beetl模板引擎入门教程
    JSON.stringify()的深度使用
    nvm 查看node版本
    去掉点击a标签时产生的虚线框
    html 设置input框的记忆功能(联想内容)
    php post和get请求
  • 原文地址:https://www.cnblogs.com/yours1103/p/3407419.html
Copyright © 2011-2022 走看看