QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#601411#7061. Poker Gametkt0506WA 1ms3828kbC++149.5kb2024-09-29 23:07:332024-09-29 23:07:33

Judging History

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

  • [2024-09-29 23:07:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2024-09-29 23:07:33]
  • 提交

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 5;
    // //   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){
        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 {5,13};
    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: 100
Accepted
time: 0ms
memory: 3628kb

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:

90
90
100
115
105

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

5
9 5 19 35 30 42 18 8 21 51 16 26 32 29 49
17 50 13 7 37 21 25 31 28 18 30 27 24 16 15
31 38 52 46 1 29 41 12 39 24 10 45 13 22 42
8 10 33 18 39 49 29 43 51 2 35 19 27 41 12
48 13 33 39 30 47 32 24 12 9 42 1 18 41 51

output:

65
115
115
100
105

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

5
51 31 17 50 24 15 25 20 22 16 44 6 19 39 28
34 1 21 10 31 15 35 8 27 51 32 23 48 24 29
39 18 27 14 31 2 35 51 44 21 24 6 43 16 19
9 44 4 19 35 47 15 51 25 20 40 8 21 6 7
49 35 11 12 44 29 22 9 16 13 4 17 32 25 7

output:

100
125
115
75
85

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

5
16 41 30 6 5 39 22 1 29 42 32 49 40 27 21
39 14 32 48 6 37 23 35 13 52 43 2 24 38 45
49 42 38 18 47 52 30 15 16 1 26 31 28 6 40
47 31 22 45 49 46 36 17 35 48 38 33 13 16 20
41 17 9 34 25 21 8 18 22 24 4 20 26 15 42

output:

90
80
100
115
115

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

5
26 38 46 4 52 15 51 7 1 30 5 3 33 47 34
22 7 15 9 5 29 32 23 30 25 33 2 1 50 4
22 44 31 33 32 39 26 5 21 15 48 2 52 37 13
21 50 12 7 43 26 32 28 42 30 20 9 35 47 8
38 12 4 33 10 25 50 37 46 36 6 40 29 48 5

output:

100
65
100
120
115

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

5
32 51 43 23 30 17 36 37 48 22 46 41 20 1 42
49 29 40 4 19 46 13 39 8 12 47 38 16 32 34
37 34 45 36 10 26 33 21 46 35 39 13 41 27 19
51 15 42 35 27 52 18 1 44 37 26 39 33 32 8
31 50 52 24 37 17 26 2 20 13 1 38 9 49 51

output:

85
105
110
100
100

result:

ok 5 lines

Test #7:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

50
13 27 25 40 35 8 4 48 24 21 23 41 28 34 46
17 24 35 47 44 39 23 51 41 26 9 8 11 25 6
46 2 15 10 45 1 32 29 4 47 14 35 49 16 22
30 43 11 47 42 28 17 39 18 15 24 5 22 12 7
7 32 43 36 17 3 1 12 34 27 35 16 29 22 45
42 38 8 45 37 22 50 33 31 49 28 20 17 40 15
17 10 30 39 18 48 32 4 26 13 27 22 3 2 8
...

output:

25
0
110
205
160

result:

ok 5 lines

Test #8:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

50
23 24 41 38 31 36 34 2 39 37 47 43 35 3 32
9 4 29 18 35 23 40 43 41 52 45 48 25 37 28
3 37 25 2 16 44 1 31 23 42 22 40 48 30 6
39 38 46 20 9 18 37 42 29 17 21 23 7 50 12
43 12 19 21 31 22 38 5 2 36 45 17 18 51 13
29 52 39 31 16 21 9 15 4 48 43 41 24 20 30
28 50 51 17 10 41 40 48 13 45 24 18 11 43...

output:

30
10
170
135
155

result:

ok 5 lines

Test #9:

score: -100
Wrong Answer
time: 1ms
memory: 3592kb

input:

50
29 37 4 16 38 19 24 34 21 11 26 48 3 39 35
26 10 13 49 9 12 14 1 2 28 11 43 47 18 19
30 43 40 29 12 22 46 6 36 35 20 2 32 23 45
51 27 39 10 2 24 52 14 7 4 38 36 25 47 21
36 19 2 3 45 47 44 5 51 30 49 35 46 6 11
32 37 30 12 34 13 45 35 42 41 8 52 16 27 2
38 30 12 13 28 19 31 26 36 5 51 34 35 41 25...

output:

10
105
45
215
125

result:

wrong answer 2nd lines differ - expected: '130', found: '105'