其他分享
首页 > 其他分享> > 多校8 D Poker Game: Decision

多校8 D Poker Game: Decision

作者:互联网

problem

暴力sg,打牌

code

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ll long long
using namespace std;
const int _=1e6+7;
// const int mod=1e9+7;
int read() {
    int x=0,f=1;char s=getchar();
    for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
    for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
    return x*f;
}
struct node {
    int x;
    char s;
};
node nbread() {
    char s[10];
    cin>>(s+1);
    int x;
    if(s[1]>='0'&&s[1]<='9') x=s[1]-'0';
    else {
        if(s[1]=='T') x=10;
        if(s[1]=='J') x=11;
        if(s[1]=='Q') x=12;
        if(s[1]=='K') x=13;
        if(s[1]=='A') x=14;
    }
    return node{x,s[2]};
}
bool cmp(node a,node b) {
    if(a.x!=b.x) return a.x<b.x;
    return a.s<b.s;
}
node dsr[56];
bool check_flower_same() {
    for(int i=1;i<5;++i)
        if(dsr[i].s!=dsr[i-1].s) return 0;
    return 1;
}
bool big_big() {
    for(int i=1;i<5;++i) {
        if(dsr[i].x==dsr[i-1].x) return 0;
    }
    return 1;
}
int rrank(node a,node b,node c,node d,node e) {
    dsr[0]=a;dsr[1]=b;dsr[2]=c;dsr[3]=d,dsr[4]=e;
    sort(dsr,dsr+5,cmp);
    // for(int i=0;i<5;++i) {
    //     cout<<dsr[i].x<<","<<dsr[i].s<<"     ";
    // } cout<<"\n";
    if(check_flower_same()) {
        if(dsr[0].x==10&&dsr[1].x==11&&dsr[2].x==12&&dsr[3].x==13&&dsr[4].x==14) return 10;
        // if(a.x=='T'&&b.x=='J'&&c.x=='Q'&&d.x=='K'&&e.x=='A') return 10;
        if(dsr[0].x==2 &&dsr[1].x==3 &&dsr[2].x==4 &&dsr[3].x==5 &&dsr[4].x==14) return 9;
        int flag=1;
        for(int i=1;i<5;++i)
            if(dsr[i].x!=dsr[i-1].x+1) flag=0;
        if(flag) return 9;
    }
    if(dsr[0].x==dsr[1].x&&dsr[1].x==dsr[2].x&&dsr[2].x==dsr[3].x) return 8;
    if(dsr[0+1].x==dsr[1+1].x&&dsr[1+1].x==dsr[2+1].x&&dsr[2+1].x==dsr[3+1].x) return 8;
    
    if(dsr[0].x==dsr[1].x&&dsr[1].x==dsr[2].x&&dsr[3].x==dsr[4].x) return 7;
    if(dsr[0].x==dsr[1].x&&dsr[2].x==dsr[3].x&&dsr[3].x==dsr[4].x) return 7;
    
    if(check_flower_same()) {
        if(big_big()) return 6;
    }
    if(dsr[0].x==2 &&dsr[1].x==3 &&dsr[2].x==4 &&dsr[3].x==5 &&dsr[4].x==14) return 5;
    int flag=1;
    for(int i=1;i<5;++i)
        if(dsr[i].x!=dsr[i-1].x+1) flag=0;
    if(flag) return 5;
    if(dsr[0].x==dsr[1].x&&dsr[1].x==dsr[2].x) return 4; 
    if(dsr[1].x==dsr[2].x&&dsr[2].x==dsr[3].x) return 4; 
    if(dsr[2].x==dsr[3].x&&dsr[3].x==dsr[4].x) return 4; 

    if(dsr[0].x==dsr[1].x&&dsr[2].x==dsr[3].x) return 3;
    if(dsr[1].x==dsr[2].x&&dsr[3].x==dsr[4].x) return 3;
    if(dsr[0].x==dsr[1].x&&dsr[3].x==dsr[4].x) return 3;

    if(dsr[0].x==dsr[1].x||dsr[1].x==dsr[2].x||dsr[2].x==dsr[3].x||dsr[3].x==dsr[4].x) return 2;

    return 1;
}
int wocao(node a,node b,node c,node d,node e) {
    dsr[0]=a;dsr[1]=b;dsr[2]=c;dsr[3]=d,dsr[4]=e;
    sort(dsr,dsr+5,cmp);
    // for(int i=0;i<5;++i) {
    //     cout<<dsr[i].x<<","<<dsr[i].s<<"     ";
    // } cout<<"\n";
    if(check_flower_same()) {
        if(dsr[0].x==10&&dsr[1].x==11&&dsr[2].x==12&&dsr[3].x==13&&dsr[4].x==14) return 0;
        // if(a.x=='T'&&b.x=='J'&&c.x=='Q'&&d.x=='K'&&e.x=='A') return 10;
        if(dsr[0].x==2 &&dsr[1].x==3 &&dsr[2].x==4 &&dsr[3].x==5 &&dsr[4].x==14) return 0;
        int flag=1;
        for(int i=1;i<5;++i)
            if(dsr[i].x!=dsr[i-1].x+1) flag=0;
        if(flag) {
            int val=0;
            for(int i=4;i>=0;--i) {
                val=val*30+dsr[i].x;
            }
            return val;
        }
    }
    if(dsr[0].x==dsr[1].x&&dsr[1].x==dsr[2].x&&dsr[2].x==dsr[3].x) {
            int val=0;
            for(int i=3;i>=0;--i) {
                val=val*30+dsr[i].x;
            }   
            val=val*30+dsr[4].x;
        return val;
    }
    if(dsr[0+1].x==dsr[1+1].x&&dsr[1+1].x==dsr[2+1].x&&dsr[2+1].x==dsr[3+1].x) {
            int val=0;
            for(int i=4;i>=1;--i) {
                val=val*30+dsr[i].x;
            }   
            val=val*30+dsr[0].x;
        return val;
    }
    if(dsr[0].x==dsr[1].x&&dsr[1].x==dsr[2].x&&dsr[3].x==dsr[4].x) {
            int val=0;
            val=val*30+dsr[0].x;
            val=val*30+dsr[0].x;
            val=val*30+dsr[0].x;
            val=val*30+dsr[3].x;
            val=val*30+dsr[3].x;
        return val;
    }
    if(dsr[0].x==dsr[1].x&&dsr[2].x==dsr[3].x&&dsr[3].x==dsr[4].x) {
            int val=0;
            val=val*30+dsr[2].x;
            val=val*30+dsr[2].x;
            val=val*30+dsr[2].x;
            val=val*30+dsr[0].x;
            val=val*30+dsr[0].x;
        return val;
    }
    if(check_flower_same()) {
        if(big_big()) {
            int val=0;
            for(int i=4;i>=0;--i) {
                val=val*30+dsr[i].x;
            }
            return val;
        }
    }
    if(dsr[0].x==2 &&dsr[1].x==3 &&dsr[2].x==4 &&dsr[3].x==5 &&dsr[4].x==14) return 0;
    int flag=1;
    for(int i=1;i<5;++i)
        if(dsr[i].x!=dsr[i-1].x+1) flag=0;
    if(flag) {
        int val=0;
        for(int i=4;i>=0;--i) {
            val=val*30+dsr[i].x;
        }
        return val;
    } 
    if(dsr[0].x==dsr[1].x&&dsr[1].x==dsr[2].x) {
          int val=0;
            val=val*30+dsr[0].x;
            val=val*30+dsr[0].x;
            val=val*30+dsr[0].x;
            val=val*30+dsr[4].x;
            val=val*30+dsr[3].x;
        return val;
    }
    if(dsr[1].x==dsr[2].x&&dsr[2].x==dsr[3].x) {
        int val=0;
            val=val*30+dsr[1].x;
            val=val*30+dsr[1].x;
            val=val*30+dsr[1].x;
            val=val*30+dsr[4].x;
            val=val*30+dsr[0].x;
        return val;
         
    }
    if(dsr[2].x==dsr[3].x&&dsr[3].x==dsr[4].x) {
        int val=0;
            val=val*30+dsr[2].x;
            val=val*30+dsr[2].x;
            val=val*30+dsr[2].x;
            val=val*30+dsr[1].x;
            val=val*30+dsr[0].x;
        return val;
         
    }

    if(dsr[0].x==dsr[1].x&&dsr[2].x==dsr[3].x) {
           int val=0;
            val=val*30+dsr[2].x;
            val=val*30+dsr[2].x;
            val=val*30+dsr[0].x;
            val=val*30+dsr[0].x;
            val=val*30+dsr[4].x;
        return val;
   
    }
    if(dsr[1].x==dsr[2].x&&dsr[3].x==dsr[4].x) {
        int val=0;
            val=val*30+dsr[4].x;
            val=val*30+dsr[4].x;
            val=val*30+dsr[1].x;
            val=val*30+dsr[1].x;
            val=val*30+dsr[0].x;
        return val;
    }
    if(dsr[0].x==dsr[1].x&&dsr[3].x==dsr[4].x) {
        int val=0;
            val=val*30+dsr[3].x;
            val=val*30+dsr[3].x;
            val=val*30+dsr[0].x;
            val=val*30+dsr[0].x;
            val=val*30+dsr[2].x;
        return val;
    }

    if(dsr[0].x==dsr[1].x) {
            int val=0;
            val=val*30+dsr[0].x;
            val=val*30+dsr[0].x;
            val=val*30+dsr[4].x;
            val=val*30+dsr[3].x;
            val=val*30+dsr[2].x;
        return val;
    }
    if(dsr[1].x==dsr[2].x) {
            int val=0;
            val=val*30+dsr[1].x;
            val=val*30+dsr[1].x;
            val=val*30+dsr[4].x;
            val=val*30+dsr[3].x;
            val=val*30+dsr[0].x;
        return val;
    }
    if(dsr[2].x==dsr[3].x) {
            int val=0;
            val=val*30+dsr[2].x;
            val=val*30+dsr[2].x;
            val=val*30+dsr[4].x;
            val=val*30+dsr[1].x;
            val=val*30+dsr[0].x;
        return val;
    }
    if(dsr[3].x==dsr[4].x) {
                    int val=0;
            val=val*30+dsr[3].x;
            val=val*30+dsr[3].x;
            val=val*30+dsr[2].x;
            val=val*30+dsr[1].x;
            val=val*30+dsr[0].x;
        return val;
    }


             int val=0;
            val=val*30+dsr[4].x;
            val=val*30+dsr[3].x;
            val=val*30+dsr[2].x;
            val=val*30+dsr[1].x;
            val=val*30+dsr[0].x;
        return val;
}
node Aa,Ab;
node Ba,Bb;
node cnt1[34],cnt2[34];
node s[100];
int v[100];
int sbsb(node a,node b,node c,node d,node e) {
    dsr[0]=a;dsr[1]=b;dsr[2]=c;dsr[3]=d,dsr[4]=e;
    sort(dsr,dsr+5,cmp);
    int sb=0;
    for(int i=4;i>=0;--i) sb=sb*30+dsr[i].x;
    return sb;
}
int pd() {
    int rk1=rrank(Aa,Ab,cnt1[0],cnt1[1],cnt1[2]);
    int rk2=rrank(Ba,Bb,cnt2[0],cnt2[1],cnt2[2]);
    if(rk1==rk2) {
        int wc1=wocao(Aa,Ab,cnt1[0],cnt1[1],cnt1[2]);
        int wc2=wocao(Ba,Bb,cnt2[0],cnt2[1],cnt2[2]);
        if(wc1==wc2) return 2;
        return wc1>=wc2;
    }
    return rk1>=rk2;
}
int dfs(int t)
{
    if(t==6) {
        // cout<<pd()<<"< ";
        return pd();//0 1 2
    }
    int vis[4]={};
    for(int i=0;i<6;i++){ 
        if(!v[i]) {
            v[i]=1;
            if(t%2==0){
                // cout<<"nb ";
                cnt1[t/2]=s[i];
            }
            else {
                // cout<<"nb ";
                cnt2[t/2]=s[i];
            }
            vis[dfs(t+1)]=1;
            v[i]=0;
        }
        if(vis[0]==1) return 1;
    }
    if(vis[0]==1) return 1;
    else if(vis[2]==1) return 2;
    return 0;
}

void solve() {
    // vis[0]=vis[1]=vis[2]=vis[3]=0;
    Aa=nbread();
    Ab=nbread();
    Ba=nbread();
    Bb=nbread();
    for(int i=0;i<6;++i) s[i]=nbread();
    int tmp=dfs(0);
    if(tmp==1) cout<<"Alice\n";
    else if(tmp==2) cout<<"Draw\n";
    else cout<<"Bob\n";
}
int main() {
    #ifdef ONLINE_JUDGE
    #else
        freopen("a.in","r",stdin);
        // freopen("a.out","w",stdout);
    #endif
    int T=read();
    while(T--) {
        solve();
    }   
    return 0;
}

标签:Poker,return,val,int,Decision,30,dsr,多校,&&
来源: https://www.cnblogs.com/acmnb/p/16589956.html