ICPC Asia Shenyang 2019 H. Texas hold'em Poker

Recently, Yang was addicted to Texas hold’em Poker. So he found a lot of people to play with him. Due to the large number of people, Yang had to change the rules of the game:

All poker cards are counted by number without suit.

Each card has a value which is one of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 (denoted A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K)

Each player drew five poker cards from a complete deck of poker (without jokers), and the possible hand values are ranked as follows from lowest to highest:

High Card. Hands which do not fit any higher category are ranked by the sum of all the cards.

Pair. 2 of the 5 cards in the hand have the same value. Hands which both contain a pair are ranked by the value of the cards forming the pair. If these values are the same, the hands are ranked by the sum of the rest cards.

Two Pairs. The hand contains 2 different pairs. Hands which both contain 2 pairs are ranked by the value of their highest pair. Hands with the same highest pair are ranked by the value of their other pair. If these values are the same the hands are ranked by the value of the remaining card.

Three of a Kind. Three of the cards in the hand have the same value. Hands which both contain three of a kind are ranked by the value of the 3 cards. Hands with the same 3 cards are ranked by the sum of the rest two cards.

Full House. 3 cards of the same value, with the remaining 2 cards forming a pair. Ranked by the value of the 3 cards. Hands with the same 3 cards are ranked by the value of the cards forming the pair.

Four of a kind. 4 cards with the same value. Ranked by the value of the 4 cards. Hands with the same 4 cards are ranked by the remaining card.

Straight. Hand contains 5 cards with consecutive values. Hands which both contain a straight are ranked by their highest card.

Royal Straight. Straight from 10 to A (10-J-Q-K-A). The largest hand!

Now, Yang has known everyone’s cards, he wants a ranking list of all poker hands. If the value of players are equal, output their names in lexicographical order. It’s guaranteed that no one’s name repeats. Can you just help him?

Input
The input consists of multiple test cases, Each test case starts with a number n (1 \le n \le 10^51≤n≤10
5
) represents the number of players, Then followed nn lines with each line two string m (1 \le |m| \le 101≤∣m∣≤10) – the name of the player s (1 \le |s| \le 101≤∣s∣≤10) the poker cards of the player.

Output
For each test case, you should output nn lines represent the ranking list.

樣例輸入 複製
3
Alice AAA109
Bob 678910
Boa 678910
樣例輸出 複製
Boa
Bob
Alice

鏈接: https://nanti.jisuanke.com/t/41408
題意: 沒什麼好說的,用優先隊列判斷大小模擬每種情況
註釋: 碼了240行必須記錄一下!!!
AC代碼:

#include <bits/stdc++.h>

#define endl '\n'
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#pragma GCC optimize("-O3")
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const int inf=0x3f3f3f3f;
const int MAXN=100050;
const ull mod=1e9+7;

struct peo {
    string name;
    int value;
    bool vis;
    int card[5];
    bool operator<(const peo& p)const {
        if(value==p.value) return name>p.name;
        return value<p.value;
    }
    void so() {
        sort(card,card+5);
    }
}p[MAXN];

int main() {
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n) {
        for(int i=0;i<n;i++) {
            p[i].vis=0;
            p[i].value=0;
            memset(p[i].card,0,sizeof(p[i].card));
            int cnt=0;
            string c;
            cin>>p[i].name>>c;
            for(int j=0;j<c.length();j++) {
                if(c[j]=='1') {
                    p[i].card[cnt++]=10;
                    j++;
                }
                else if(c[j]>='3'&&c[j]<='9') {
                    p[i].card[cnt++]=c[j]-48;
                }
                else if(c[j]=='2') {
                    p[i].card[cnt++]=2;
                }
                else if(c[j]=='A') {
                    p[i].card[cnt++]=1;
                }
                else if(c[j]=='J') {
                    p[i].card[cnt++]=11;
                }
                else if(c[j]=='Q') {
                    p[i].card[cnt++]=12;
                }
                else if(c[j]='K') {
                    p[i].card[cnt++]=13;
                }
            }
            p[i].so();
        }
        priority_queue <peo> que;
        for(int i=0;i<n;i++) {
            if(p[i].vis==1) continue;
            if(p[i].card[0]==1&&p[i].card[1]==10&&p[i].card[2]==11&&p[i].card[3]==12&&p[i].card[4]==13) {
                p[i].value=999;
                p[i].vis=1;
                que.push(p[i]);
            }
            if(p[i].card[0]==9&&p[i].card[1]==10&&p[i].card[2]==11&&p[i].card[3]==12&&p[i].card[4]==13) {
                p[i].value=13;
                p[i].vis=1;
                que.push(p[i]);
            }
            if(p[i].card[0]==8&&p[i].card[1]==9&&p[i].card[2]==10&&p[i].card[3]==11&&p[i].card[4]==12) {
                p[i].value=12;
                p[i].vis=1;
                que.push(p[i]);
            }
            if(p[i].card[0]==7&&p[i].card[1]==8&&p[i].card[2]==9&&p[i].card[3]==10&&p[i].card[4]==11) {
                p[i].value=11;
                p[i].vis=1;
                que.push(p[i]);
            }
            if(p[i].card[0]==6&&p[i].card[1]==7&&p[i].card[2]==8&&p[i].card[3]==9&&p[i].card[4]==10) {
                p[i].value=10;
                p[i].vis=1;
                que.push(p[i]);
            }
            if(p[i].card[0]==5&&p[i].card[1]==6&&p[i].card[2]==7&&p[i].card[3]==8&&p[i].card[4]==9) {
                p[i].value=9;
                p[i].vis=1;
                que.push(p[i]);
            }
            if(p[i].card[0]==4&&p[i].card[1]==5&&p[i].card[2]==6&&p[i].card[3]==7&&p[i].card[4]==8) {
                p[i].value=8;
                p[i].vis=1;
                que.push(p[i]);
            }
            if(p[i].card[0]==3&&p[i].card[1]==4&&p[i].card[2]==5&&p[i].card[3]==6&&p[i].card[4]==7) {
                p[i].value=7;
                p[i].vis=1;
                que.push(p[i]);
            }
            if(p[i].card[0]==2&&p[i].card[1]==3&&p[i].card[2]==4&&p[i].card[3]==5&&p[i].card[4]==6) {
                p[i].value=6;
                p[i].vis=1;
                que.push(p[i]);
            }
            if(p[i].card[0]==1&&p[i].card[1]==2&&p[i].card[2]==3&&p[i].card[3]==4&&p[i].card[4]==5) {
                p[i].value=5;
                p[i].vis=1;
                que.push(p[i]);
            }
        }
        while(!que.empty()) {
            cout<<que.top().name<<endl;
            que.pop();
        }
        for(int i=0;i<n;i++) {
            if(p[i].vis==1) continue;
            if(p[i].card[0]==p[i].card[1]&&p[i].card[1]==p[i].card[2]&&p[i].card[2]==p[i].card[3]) {
                p[i].value=p[i].card[0]*1000+p[i].card[4];
                p[i].vis=1;
                que.push(p[i]);
            }
            else if(p[i].card[1]==p[i].card[2]&&p[i].card[2]==p[i].card[3]&&p[i].card[3]==p[i].card[4]) {
                p[i].value=p[i].card[1]*1000+p[i].card[0];
                p[i].vis=1;
                que.push(p[i]);
            }
        }
        while(!que.empty()) {
            cout<<que.top().name<<endl;
            que.pop();
        }
        for(int i=0;i<n;i++) {
            if(p[i].vis==1) continue;
            if(p[i].card[0]==p[i].card[1]&&p[i].card[1]==p[i].card[2]&&p[i].card[3]==p[i].card[4]) {
                p[i].value=p[i].card[0]*1000+p[i].card[3];
                p[i].vis=1;
                que.push(p[i]);
            }
            else if(p[i].card[2]==p[i].card[3]&&p[i].card[3]==p[i].card[4]&&p[i].card[0]==p[i].card[1]) {
                p[i].value=p[i].card[2]*1000+p[i].card[0];
                p[i].vis=1;
                que.push(p[i]);
            }
        }
        while(!que.empty()) {
            cout<<que.top().name<<endl;
            que.pop();
        }
        for(int i=0;i<n;i++) {
            if(p[i].vis==1) continue;
            if(p[i].card[0]==p[i].card[1]&&p[i].card[1]==p[i].card[2]) {
                p[i].value=p[i].card[0]*1000+p[i].card[3]+p[i].card[4];
                p[i].vis=1;
                que.push(p[i]);
            }
            else if(p[i].card[1]==p[i].card[2]&&p[i].card[2]==p[i].card[3]) {
                p[i].value=p[i].card[1]*1000+p[i].card[0]+p[i].card[4];
                p[i].vis=1;
                que.push(p[i]);
            }
            else if(p[i].card[2]==p[i].card[3]&&p[i].card[3]==p[i].card[4]) {
                p[i].value=p[i].card[2]*1000+p[i].card[0]+p[i].card[1];
                p[i].vis=1;
                que.push(p[i]);
            }
        }
        while(!que.empty()) {
            cout<<que.top().name<<endl;
            que.pop();
        }
        for(int i=0;i<n;i++) {
            if(p[i].vis==1) continue;
            if(p[i].card[0]==p[i].card[1]&&p[i].card[2]==p[i].card[3]) {
                p[i].value=p[i].card[2]*10000+p[i].card[0]*100+p[i].card[4];
                p[i].vis=1;
                que.push(p[i]);
            }
            else if(p[i].card[1]==p[i].card[2]&&p[i].card[3]==p[i].card[4]) {
                p[i].value=p[i].card[3]*10000+p[i].card[1]*100+p[i].card[0];
                p[i].vis=1;
                que.push(p[i]);
            }
            else if(p[i].card[0]==p[i].card[1]&&p[i].card[3]==p[i].card[4]) {
                p[i].value=p[i].card[3]*10000+p[i].card[0]*100+p[i].card[2];
                p[i].vis=1;
                que.push(p[i]);
            }
        }
        while(!que.empty()) {
            cout<<que.top().name<<endl;
            que.pop();
        }
        for(int i=0;i<n;i++) {
            if(p[i].vis==1) continue;
            if(p[i].card[0]==p[i].card[1]) {
                p[i].value=p[i].card[0]*1000+p[i].card[2]+p[i].card[3]+p[i].card[4];
                p[i].vis=1;
                que.push(p[i]);
            }
            else if(p[i].card[1]==p[i].card[2]) {
                p[i].value=p[i].card[1]*1000+p[i].card[0]+p[i].card[3]+p[i].card[4];
                p[i].vis=1;
                que.push(p[i]);
            }
            else if(p[i].card[2]==p[i].card[3]) {
                p[i].value=p[i].card[2]*1000+p[i].card[0]+p[i].card[1]+p[i].card[4];
                p[i].vis=1;
                que.push(p[i]);
            }
            else if(p[i].card[3]==p[i].card[4]) {
                p[i].value=p[i].card[3]*1000+p[i].card[0]+p[i].card[1]+p[i].card[2];
                p[i].vis=1;
                que.push(p[i]);
            }
        }
        while(!que.empty()) {
            cout<<que.top().name<<endl;
            que.pop();
        }
        for(int i=0;i<n;i++) {
            if(p[i].vis==1) continue;
            p[i].value=p[i].card[0]+p[i].card[1]+p[i].card[2]+p[i].card[3]+p[i].card[4];
            que.push(p[i]);
        }
        while(!que.empty()) {
            cout<<que.top().name<<endl;
            que.pop();
        }
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章