UVa 131 the Psychic Poker Player: Enumerating & simulating good questions

Source: Internet
Author: User
Tags bool flush printf time limit

131-the Psychic Poker Player

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_ problem&problem=67

In 5-card draw Poker, a player is dealt a hand of five cards (the which may being looked at). The player may then discard between zero and five of him or her cards and have them replaced by the same number of cards F Rom the top of the deck (which are face down). The object is to maximize the value of the final hand. The different values of hands in poker are given at the "end of" this problem.

Normally the player cannot the cards in the deck and so must with probability to decide which to cards. In this problem, we imagine that's poker player is psychic and knows which cards to the top of the are. Write a program which advises the player which cards to discard so as to maximize the value of the resulting hand.

Input and Output

Input would consist of a series of lines, each containing the initial five cards in the hand then the "a" five on t OP of the deck. Each card is represented as a two-character code. The character is the Face-value (A=ace, 2-9, t=10, J=jack, Q=queen, k=king) and the second character are the suit (c= Clubs, D=diamonds, H=hearts, S=spades). Cards'll is separated by single spaces. Each input line would be a single valid deck, which is there would be no duplicate cards with each hand and deck.

Each line of input should produce one line of output, consisting of the initial hand, the top five cards on the deck, and The best value of hand is possible. The Input is terminated by the end of file.

Use the sample input and output as a guide. The "Order of" the "cards in" the player's hand is irrelevant, but the "the" of the cards in the deck is important B Ecause the discarded cards must is replaced from the top of the deck. Also Note This examples of all types of hands appear in the sample output, with the hands shown in decreasing order of Val Ue.

Sample Input

TH JH QC QD QS QH KH ah 2S 6S
2H 2S 3H 3S 3C 2D 3D 6C 9C TH
2H 2S 3H 3S 3C 2D 9C 3D 6C then
2H AD 5H AC 7H AH 6H 9H 4H 3C
AC 2D 9C 3S kd 5S 4D KS as 4C
ks AH 2H 3C 4H KC 2C TC 2D as
AH 2C 9S AD 3C QH KS JS JD KD
6C 9C 8C 2D 7C 2H TC 4C 9S AH
3D 5S 2H QD TD 6S KH 9H AD QH

Sample Output

hand:th JH QC QD QS deck:qh KH AH 2S 6S best Hand:straight-flush
hand:2h 2S 3H 3S 3C deck:2d 3D 6C 9C TH Best Han  D:four-of-a-kind
hand:2h 2S 3H 3S 3C deck:2d 9C 3D 6C TH best hand:full-house
hand:2h AD 5H AC 7H deck:ah 6H 9H 4H 3C Best Hand:flush
hand:ac 2D 9C 3S KD deck:5s 4D KS as 4C best hand:straight
hand:ks AH 2H 3C 4H Deck : KC 2C TC 2D as best hand:three-of-a-kind
hand:ah 2C 9S AD 3C deck:qh KS JS JD KD best Hand:two-pairs
hand:6 9C 8C 2D 7C deck:2h TC 4C 9S AH best Hand:one-pair
hand:3d 5S 2H QD TD deck:6s KH 9H AD QH Best Hand:highest-ca Rd

Learn English:

8 Straight-flush Flush: one hand with the flower of five cards + five card points consecutive CIS 7 four-of-a-kind four the same brand 6 Full-house Full House red: three cards plus a pair of points (at this time there are 2 different points of cards) 5 flush          Five cards of the same flower 4 straight: Five card points consecutive Shun Zi 3 three-of-a-kind three identical cards 2 Two-pairs two pairs (at this time there are 3 different points of cards) 1 One-pair A pair of pairs 0 Highest-card all the above conditions do not match

1. Enumeration using binary.

2. According to the title of the sample given the order to determine the type of hand in the card, first judged the priority.

3. First pretreatment: Statistics the largest number of points, different flowers, different points. And then judge.

Note: When judging whether it is a cis, a can be placed first, or can be placed at the end (that is, the back of K).

Complete code:

/*0.019s*/#include <cstdio> #include <cstring> const int N = 20;  const char ANSWER[][20] = {"Highest-card", "One-pair", "Two-pairs", "Three-of-a-kind", "straight", "flush",  
"Full-house", "Four-of-a-kind", "Straight-flush"};  
    
This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45367.htm const int bas_two[] = {16, 8, 4, 2, 1};  
    struct Card {char name[5];  
int number,suit;  
    
} Hand[n];  
Char Str[n];  
    
int a[n], b[n], c[n];  
    int Is_number (char c) {if (c = = ' A ') return 1;  
    if (c = = ' T ') return 10;  
    if (c = = ' J ') return 11;  
    if (c = = ' Q ') return 12;  
    if (c = = ' K ') return 13;  
return C & 15;  
    int Is_suit (char c) {if (c = = ' C ') return 0;  
    if (c = = ' D ') return 1;  
    if (c = = ' H ') return 2; return 3;  
    ' S '} void handle (int cur, char str[]) {strcpy (hand[cur].name, str);  
    Hand[cur].number = Is_number (str[0]); Hand[cur].sUit = Is_suit (str[1]);  
    BOOL Maxlink_num (int num[])///to detect {BOOL flag;  
        for (int i = 1; i < i++) {if (Num[i] > 1) return false;  
            if (num[i] = = 1) {flag = true;  
                    for (int j = 1; j < 5; J +) {if (num[i + j]!= 1) {  
                    Flag = false;  
                Break  
        } if (flag) return true;  } if (num[10] = = 1 && num[11] = = 1 && num[12] = 1 && num[13] = = 1 && num[1]  
    = = 1) return true;  
return false;  
    int judge (int cur) {memset (A, 0, sizeof (a));  
    memset (b, 0, sizeof (b));  
    memset (c, 0, sizeof (c));  
        for (int i = 0; i < 5; i++) {if (Cur/bas_two[i]) b[i] = 0;  
        else b[i] = 1;  
    Cur%= bas_two[i]; int cnt = 0; for (int i = 0; CNT < 5; i++) {if (!)  
            B[i]) {a[hand[i].number]++;  
            c[hand[i].suit]++;  
        cnt++;  
    }///Judge color and num;  int max = 0,flag_color = 0, Flag_num = 0;///Maximum number of identical points, different flowers, different points for (int i = 1; i < i++) {if (A[i] >  
        max) max = a[i];  
    if (A[i]) flag_num++;  
    for (int i = 0; i < 4; i++) if (c[i]) flag_color++;  
    BOOL link = maxlink_num (A);  
    if (Flag_color = = 1 && link) return 8;///5 with the same flower and is the CIS if (max = = 4) return 7;///4 the same point if (max = = 3 && flag_num = 2) return 6;///3 the same point plus a pair (with 2 different points of cards) if (Flag_color = 1) return 5;/ 5 with Flower if (link) return 4;///cis if (max = 3) return 3;///3 same point if (m Ax = = 2 && flag_num = 3) return 2;///two pairs (with 3 different points) if (max = 2) return 1;///Pair return 0;  
    int main () {int max = 0, flag = 0;  
        while (true) {memset (hand, 0, sizeof (hand));  
        Max = flag = 0; for (int i = 0; i < i++) {if (scanf ("%s", str)!= 1) {FLA  
                g = 1;  
            Break  
        } handle (I, str);  
        } if (flag) break;  
            for (int i = 0; i < i++)///enum {flag = judge (i);  
        if (Flag > Max) max = flag;  
        }//Print printf ("Hand:");  
        for (int i = 0; i < 5; i++) printf ("%s", hand[i].name);  
        printf ("Deck:");  
        for (int i = 5; i < i++) printf ("%s", hand[i].name);  
    printf ("Best hand:%s\n", Answer[max]);  
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.