[BZOJ4801]打牌 博弈搜索

来源:互联网 发布:windows桌面文件丢失 编辑:程序博客网 时间:2024/05/06 00:52

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

#include <bits/stdc++.h>#define INF 2147483647using 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
原创粉丝点击