QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#601389#7061. Poker Gametkt0506WA 0ms3572kbC++149.6kb2024-09-29 22:49:482024-09-29 22:49:48

Judging History

你现在查看的是最新测评结果

  • [2024-09-29 22:49:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3572kb
  • [2024-09-29 22:49:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int suit(int a){
    return (a-1)/13;
}

int Rank(int a){
    if(a%13 == 1)return 13;
    else return (a-1)%13;
}


// Detect values
int isPair(vector<int>hand, vector<int>comm){ // same pair? 
    vector<int>cnt(14,0);
    for(int e : hand)cnt[Rank(e)]++;
    for(int e : comm)cnt[Rank(e)]++;
    for(int i=13; i>=0; i--)if(cnt[i]>=2)return i;
    return 0;
}

int isThree(vector<int>hand, vector<int>comm){
    vector<int>cnt(14,0);
    for(int e : hand)cnt[Rank(e)]++;
    for(int e : comm)cnt[Rank(e)]++;
    for(int i=13; i>=0; i--)if(cnt[i]>=3)return i;
    return 0;
}

int isFlush(vector<int>hand, vector<int>comm){
    vector<int>cnt(4,0);
    for(int e : hand)cnt[suit(e)]++;
    for(int e : comm)cnt[suit(e)]++;
    int mx = 0;
    for(int i=0; i<4; i++){
        if(cnt[i]>=5){
            for(int e : hand)if(suit(e)==i)mx = max(mx, Rank(e));
            for(int e : comm)if(suit(e)==i)mx = max(mx, Rank(e));
        }
    }
    return mx;
}

int isStraight(vector<int>hand, vector<int>comm){
    vector<int>cnt(14,0);
    for(int e : hand)cnt[Rank(e)]++;
    for(int e : comm)cnt[Rank(e)]++;
    int mx = 0;
    for(int i=1; i+4<=13; i++){
        bool flag = cnt[i];
        for(int j=i+1; j<=i+4; j++)flag &= cnt[j];
        if(flag)mx = max(mx, i+4);
    }
    if(cnt[13] && cnt[1] && cnt[2] && cnt[3] && cnt[4])mx = max(mx, 4);
    return mx;
}

int isStraightFlush(vector<int>hand, vector<int>comm){
    vector<int>cnt(54,0);
    for(int e : hand)cnt[e]++;
    for(int e : comm)cnt[e]++;
    int mx = 0;
    for(int i=0; i<4; i++){
        vector<int>tmp;
        for(int j=i*13+1; j<=(i+1)*13; j++)if(cnt[j])tmp.push_back(j);
        if(isStraight(tmp,{}))mx = 13;
    }
    return mx;
}

int needFlush(vector<int>hand, vector<int>comm, vector<int>hole){
    vector<int>cnt(4,0), cnt2(4,0);
    for(int e : hand)cnt[suit(e)]++;
    for(int e : comm)cnt[suit(e)]++;
    for(int e : hole)cnt2[suit(e)]++;
    int mx = 5;
    for(int i=0; i<4; i++)if(5-cnt[i]<=13-cnt2[i]-cnt[i])mx = min(mx, 5-cnt[i]);
    return mx;
}

int needStraight(vector<int>hand, vector<int>comm, vector<int>hole){
    vector<int>cnt(14,0), cnt2(14,0);
    for(int e : hand)cnt[Rank(e)]++;
    for(int e : comm)cnt[Rank(e)]++;
    for(int e : hole)cnt2[Rank(e)]++;
    int mx = 5;
    for(int i=1; i+4<=13; i++){
        int tot = 0;
        if(cnt[i])tot++;
        for(int j=i+1; j<=i+4; j++)if(cnt[j])tot++;
        bool flag = 1;
        for(int j=i; j<=i+1; j++){
            if(!cnt[j] && cnt2[j]==4)flag = 0;
        }
        if(!flag)continue;
        mx = min(mx, 5-tot);
    }
    int tot = 0;
    bool flag = 1;
    for(int j=1; j<=4; j++)if(!cnt[j] && cnt2[j]==4)flag = 0;
    if(!cnt[13] && cnt2[13] == 4)flag = 0;
    if(cnt[13])tot++;
    if(cnt[1])tot++;
    if(cnt[2])tot++;
    if(cnt[3])tot++;
    if(cnt[4])tot++;
    if(flag)mx = min(mx, 5-tot);
    return mx;
}




// Strategy 1 
int playA(int pot, vector<int>hand, vector<int>comm, vector<int>hole, int round){
    if(round == 1){
        if(pot < 15 || (suit(hand[0]) != suit(hand[1])))return 0;
        return min(pot,5);
    }
    // if(round == 2){
    // //   return min(pot,5);
    //     if(isPair(hand, comm) || needFlush(hand, comm, hole) <= 2|| needStraight(hand, comm, hole) <= 2)return min(pot, 5);
    //     return 0;
    // }
    if(round == 3 || round == 2){
        if(isPair(hand, comm) || isThree(hand, comm) || isFlush(hand, comm) || isStraight(hand,comm) || isStraightFlush(hand,comm))return min(pot, 5);
        return 0;
    }
}

// Strategy 2
int playB(int pot, vector<int>hand, vector<int>comm, vector<int>hole, int round){
    if(round == 1){
        if(pot >= 15)return 5;
        if(Rank(hand[0]) == 13 && Rank(hand[1]) == 13)return pot;
        return 0;
    }
    if(round == 2){
        if(isPair(hand, comm) || isThree(hand, comm) || isFlush(hand, comm) || isStraight(hand,comm) || isStraightFlush(hand,comm))return min(pot, 5);
        if(needFlush(hand, comm, hole) == 1 || needStraight(hand,comm, hole) == 1)return min(pot, 5);
        return 0;
    }
    if(round == 3){
        vector<int>cnt(4,0);
        for(int e : comm)cnt[suit(e)]++;
        for(int i=0; i<4; i++)if(cnt[i] >= 4)return 0;
        return min(pot, 5);
    }
}

// Strategy 3
int playC(int pot, vector<int>hand, vector<int>comm, vector<int>hole, int round){
    if(round == 1){
        if(Rank(hand[0]) == 13 || Rank(hand[1]) == 13 || abs(Rank(hand[0])-Rank(hand[1])) < 3){
          if(pot >= 15)return 5;
          else return pot;
        }
        return 0;
    }
    if(round ==2){
        vector<int>cnt(14,0);
        for(int e : comm)cnt[Rank(e)]++;
        for(int i=1; i<=13; i++){
            if(cnt[i] >= 2){
                bool flag = 0;
                for(int e : hand)if(Rank(e) == i)flag = 1;
                if(!flag)return 0;
            }
        }
        return min(pot,5);
    }
    if(round == 3)return min(pot, 5);
}

// Strategy 4
int playD(int pot, vector<int>hand, vector<int>comm, vector<int>hole, int round){
    if(round == 1){
        for(int e : hand)if(Rank(e) > 10){
            if(pot >= 15)return 5;
            else return pot;
        }
        return 0;
    }
    if(round == 2){
        int mx = 0;
        for(int e : hand)mx = max(mx, Rank(e));
        int mx2 = 0;
        for(int e : comm)mx2 = max(mx2, Rank(e));
        // cout << mx << " " << mx2 << "\n";
        if(mx > mx2)return min(pot, 5);
        for(int e : hand)if(Rank(e) == mx2)return min(pot,5);
        return 0;
    }
    if(round == 3){
        if(isThree(hand, comm) || isFlush(hand, comm) || isStraight(hand,comm) || isStraightFlush(hand,comm))return min(pot, 5);
        vector<int>tmp;
        for(int e : comm)tmp.push_back(Rank(e));
        sort(tmp.begin(), tmp.end());
        if(isPair(hand, comm) > tmp[2])return min(pot, 5);
        return 0;
    }
}

// Strategy 5
int playE(int pot, vector<int>hand, vector<int>comm, vector<int>hole, int round, int ppl){
    if(round == 1){
        if(ppl==2){
            if(pot >= 15)return 5;
            else return pot;
        }
        else return 0;
    }
    return min(pot,5);
}

vector<bool>isFold(5,0), isAllin(5,0);
vector<int>coin(5,100);
vector<int>Hand[5], Comm;
int Ppl = 5, win = 0;

void play(int a, int r){
    if(isFold[a] || isAllin[a])return ;
    int v;
    if(a==0)v = playA(coin[0], Hand[0], Comm, {},r);
    else if(a==1)v = playB(coin[1], Hand[1], Comm, {},r);
    else if(a==2)v = playC(coin[2], Hand[2], Comm, {},r);
    else if(a==3)v = playD(coin[3], Hand[3], Comm, {},r);
    else v = playE(coin[4], Hand[4], Comm, {},r, Ppl);
    win += v;
    // cout << "PLAY: " << a << " " << v << "\n";
    coin[a] -= v;
    if(v==0){
        isFold[a] = 1;
        Ppl--;
    }else{
        if(coin[a] == 0)isAllin[a] = 1;
    }
}

typedef pair<int,int> pii;
pii calc(int a){
    if(isStraightFlush(Hand[a],Comm))return {6,isStraightFlush(Hand[a],Comm)};
    if(isFlush(Hand[a],Comm))return {5,isFlush(Hand[a],Comm)};
    if(isStraight(Hand[a],Comm))return {4,isStraight(Hand[a],Comm)};
    if(isThree(Hand[a],Comm))return {3,isThree(Hand[a],Comm)};
    if(isPair(Hand[a],Comm))return {2,isPair(Hand[a],Comm)};
    int mx = 0;
    for(int e : Hand[a])mx = max(mx, Rank(e));
    return {1,mx};
}

int main(){
    int n;
    cin >> n;

    while(n--){
        // for(int e : coin)cout << e << ' ';
        // cout << "\n";
        // cout << "\nNEW ROUND\n";
        Comm.clear();
        Ppl = 5;
        win = 0;
        for(int i=0; i<5; i++){
            Hand[i].clear();
            isFold[i] = isAllin[i] = 0;
        }

        vector<int>a(15);
        for(int i=0; i<15; i++)cin >> a[i];

        // for(int i=0; i<15; i++)cout << Rank(a[i])+1 << " " << suit(a[i]) << "\n";
        // cout << "\n";
        
        int idx = 0;
        for(int i=0; i<5; i++){
            if(!coin[i]){
                Ppl--;
                isFold[i] = 1;
                continue;
            }
            Hand[i].push_back(a[idx]);
            Hand[i].push_back(a[idx+1]);
            idx += 2;
        }

        // round 1
        for(int i=0; i<4; i++)play(i,1);
        if(Ppl == 1){
            coin[4] += win;
            continue;
        }else play(4,1);

        // round 2
        Comm.push_back(a[idx]);
        Comm.push_back(a[idx+1]);
        Comm.push_back(a[idx+2]);
        idx += 3;
        bool endFlag = 0;
        for(int i=0; i<5; i++){
            if(Ppl == 1 && !isFold[i]){
                coin[i] += win;
                endFlag = 1;
                break; 
            }
            play(i,2);
        }
        if(endFlag)continue;

        // round 3
        Comm.push_back(a[idx]);
        Comm.push_back(a[idx+1]);
        for(int i=0; i<5; i++){
            if(Ppl == 1 && !isFold[i]){
                coin[i] += win;
                endFlag = 1;
                break; 
            }
            play(i,3);
        }
        if(endFlag)continue;

        // final battle
        int idx2 = -1, scr = 0, scr2 = 0;
        for(int i=0; i<5; i++){
            if(isFold[i])continue;
            pii res = calc(i);
            if(idx == -1 || res.first > scr || (res.first == scr && res.second >= scr2)){
                idx2 = i;
                scr = res.first;
                scr2 = res.second;
            }
        }
        // cout << "WIN: " << idx2 << "\n";
        coin[idx2] += win;
    }
    for(int e : coin)cout << e << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3572kb

input:

2
1 2 8 10 3 11 15 12 14 27 42 43 45 48 13
14 2 8 10 3 11 5 23 1 27 42 43 13 45 48

output:

95
90
100
110
105

result:

wrong answer 1st lines differ - expected: '90', found: '95'