[BZOJ4801]打牌 博弈搜索

出题人qqq说,分类讨论是大坑
实力作死写了一发分类讨论,发现真tm是大坑
博弈搜索多好啊

#include <bits/stdc++.h>
#define INF 2147483647
using namespace std;
inline int rd() { int r; scanf("%d",&r); return r; }
char s[10],t[10];
int a,b,c,d,A,B,C,D,x[10];
int get() {
    scanf("%s",s+1);
    if (s[1] == 'A') return 1;
    if (s[1] == 'T') return 10;
    if (s[1] == 'J') return 11;
    if (s[1] == 'Q') return 12;
    if (s[1] == 'K') return 13;
    return s[1]-'0';
}

int calc(int x,int y,int xh) {
    if (x == y) {
        if (xh) return x; else return -x;
    }
    if (x == 1) return 1;
    if (y == 1) return -1;
    if (x>=y) return x; else return -y;
}


int o(int x,int y,int xh) {
    if (x == y) return xh;
    if (x == 1) return 1;
    if (y == 1) return 0;
    if (x>=y) return 1; else return 0;
}

int dfs(int u,int dep,int v,int xxx) {
    int ret;
    if (u == 1 && dep == 3) return v;
    if (u == 1) {
        ret = -INF;
        if (!A) {
            x[dep] = a, A = 1; 
            ret = max(ret, dfs(0,dep,v,xxx));
            x[dep] = 0, A = 0;
        }
        if (!B) {
            x[dep] = b, B = 1;
            ret = max(ret, dfs(0,dep,v,xxx));
            x[dep] = 0, B = 0;
        }
        return ret;
    }

    if (u == 0) {
        ret = INF;
        if (!C) {
            C = 1;
            int no = o(x[dep], c, xxx);
            ret = min(ret, dfs(1,dep+1,v+calc(x[dep],c,xxx),no));
            C = 0;
        }
        if (!D) {
            D = 1;
            int no = o(x[dep], d, xxx);
            ret = min(ret, dfs(1,dep+1,v+calc(x[dep],d,xxx),no));
            D = 0;
        }
        return ret;
    }

    assert(0); return 0;
}
int main() {
    int T = rd();
    while (T--) {
        a = get(), b = get();
        if (a>b) swap(a,b);
        c = get(), d = get();
        if (c>d) swap(c,d);

        int ans = dfs(1,1,0,1);
        printf("%d\n",ans);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值