AOJ2535: Texas hold 'em 题解

这就是一道纯粹的巨模拟题
非常暴力的进行枚举,剩下的两张牌有4544÷2=990 种可能性
从七张里面选五张有C75=1176 种可能性,这两个相乘肯定是不会炸的
然后就巨模拟就好了
注意一点,在比顺子的时候,A2345是最小的,如果用比较rank最高的牌的方式比较,记得把A放到最后面

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pii pair<double,double>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=348;
const double eps=1e-10;
const double pi=acos(-1);

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int val[300];

struct Card
{
    char type;char num;
    inline bool operator == (const Card &other) const {return num==other.num;}
    inline bool operator < (const Card &other) const {return val[num]<val[other.num];}
    inline bool operator > (const Card &other) const {return val[num]>val[other.num];}
}my[10],oppo[10],all[10],other[10],seven[10];

struct Hand
{
    Card a[10];
}mybest,oppobest;

inline bool isRoyalStraight(Hand cur)
{
    int i,j;
    for (i=1;i<=4;i++)
        for (j=i+1;j<=5;j++)
            if (cur.a[i]==cur.a[j]) return false;
    for (i=1;i<=5;i++)
        if (!(cur.a[i].num=='T' || cur.a[i].num=='J' || cur.a[i].num=='Q' || cur.a[i].num=='K' || cur.a[i].num=='A')) return false;
    return true;
}

inline bool isminStraight(Hand cur)
{
    int i,j;
    for (i=1;i<=4;i++)
        for (j=i+1;j<=5;j++)
            if (cur.a[i]==cur.a[j]) return false;
    for (i=1;i<=5;i++)
        if (!(cur.a[i].num=='A' || ('2'<=cur.a[i].num && cur.a[i].num<='5'))) return false;
    return true;
}

inline bool isStraight(Hand cur)
{
    if (isminStraight(cur) || isRoyalStraight(cur)) return true;
    for (register int i=1;i<=4;i++) if (val[cur.a[i+1].num]!=val[cur.a[i].num]+1) return false;
    return true;
}

inline bool isFlush(Hand cur)
{
    for (register int i=2;i<=5;i++) if (cur.a[1].type!=cur.a[i].type) return false;
    return true;
}

inline bool isStraightFlush(Hand cur) {return (isStraight(cur) && isFlush(cur));}

inline bool isBomb(Hand cur)
{
    if (cur.a[1]==cur.a[2] && cur.a[1]==cur.a[3] && cur.a[1]==cur.a[4]) return true;
    if (cur.a[2]==cur.a[3] && cur.a[2]==cur.a[4] && cur.a[2]==cur.a[5]) return true;
    return false;
}

inline bool isFullHouse(Hand cur)
{
    if (cur.a[1]==cur.a[2] && cur.a[1]==cur.a[3] && cur.a[4]==cur.a[5]) return true;
    if (cur.a[1]==cur.a[2] && cur.a[3]==cur.a[4] && cur.a[3]==cur.a[5]) return true;
    return false;
}

inline bool isThree(Hand cur)
{
    if (cur.a[1]==cur.a[2] && cur.a[1]==cur.a[3]) return true;
    if (cur.a[2]==cur.a[3] && cur.a[3]==cur.a[4]) return true;
    if (cur.a[3]==cur.a[4] && cur.a[4]==cur.a[5]) return true;
    return false;
}

inline bool isTwoPairs(Hand cur)
{
    if (cur.a[1]==cur.a[2] && cur.a[3]==cur.a[4]) return true;
    if (cur.a[1]==cur.a[2] && cur.a[4]==cur.a[5]) return true;
    if (cur.a[2]==cur.a[3] && cur.a[4]==cur.a[5]) return true;
    return false;
}

inline bool isPair(Hand cur)
{
    int i,j;
    for (i=1;i<=4;i++)
        for (j=i+1;j<=5;j++)
            if (cur.a[i]==cur.a[j]) return true;
    return false;
}

inline int judgetype(Hand cur)
{
    if (isStraightFlush(cur)) return 1;
    if (isBomb(cur)) return 2;
    if (isFullHouse(cur)) return 3;
    if (isFlush(cur)) return 4;
    if (isStraight(cur)) return 5;
    if (isThree(cur)) return 6;
    if (isTwoPairs(cur)) return 7;
    if (isPair(cur)) return 8;
    return 9;
}

inline bool Same(Card cur)
{
    int i;
    for (i=1;i<=2;i++) if (my[i]==cur && my[i].type==cur.type) return true;
    for (i=1;i<=2;i++) if (oppo[i]==cur && oppo[i].type==cur.type) return true;
    for (i=1;i<=3;i++) if (all[i]==cur && all[i].type==cur.type) return true;
    return false;
}

inline int compare_hand(Hand x,Hand y)
{
    int t1=judgetype(x),t2=judgetype(y);
    if (t1!=t2)
        if (t1>t2) return 0; else return 1;
    if (t1==1 || t1==5)
    {
        if (isminStraight(x))
        {
            Card tmp=x.a[5];
            for (register int i=4;i>=1;i--) x.a[i+1]=x.a[i];
            x.a[1]=tmp;
        }
        if (isminStraight(y))
        {
            Card tmp=y.a[5];
            for (register int i=4;i>=1;i--) y.a[i+1]=y.a[i];
            y.a[1]=tmp;
        }
        if (x.a[5]>y.a[5]) return 1;
        if (x.a[5]<y.a[5]) return 0;
        return 2;
    }
    if (t1==2)
    {
        int xv1,xv2,yv1,yv2,V1,V2;
        if (x.a[1]==x.a[2]) xv1=val[x.a[1].num],xv2=val[x.a[5].num]; else xv1=val[x.a[2].num],xv2=val[x.a[1].num];
        if (y.a[1]==y.a[2]) yv1=val[y.a[1].num],yv2=val[y.a[5].num]; else yv1=val[y.a[2].num],yv2=val[y.a[1].num];
        V1=xv1*10000+xv2;V2=yv1*10000+yv2;
        if (V1>V2) return 1;
        if (V1<V2) return 0;
        return 2;
    }
    if (t1==3)
    {
        int xv1,xv2,yv1,yv2,V1,V2;
        if (x.a[1]==x.a[2] && x.a[1]==x.a[3]) xv1=val[x.a[1].num],xv2=val[x.a[4].num]; else xv1=val[x.a[3].num],xv2=val[x.a[1].num];
        if (y.a[1]==y.a[2] && y.a[1]==y.a[3]) yv1=val[y.a[1].num],yv2=val[y.a[4].num]; else yv1=val[y.a[3].num],yv2=val[y.a[1].num];
        V1=xv1*10000+xv2;V2=yv1*10000+yv2;
        if (V1>V2) return 1;
        if (V1<V2) return 0;
        return 2;
    }
    if (t1==4 || t1==9)
    {
        for (register int i=5;i>=1;i--)
        {
            if (x.a[i]>y.a[i]) return 1;
            if (x.a[i]<y.a[i]) return 0;
        }
        return 2;
    }
    if (t1==6)
    {
        int xv1,xv2,xv3,yv1,yv2,yv3,V1,V2;
        if (x.a[1]==x.a[2] && x.a[2]==x.a[3]) xv1=val[x.a[1].num],xv2=val[x.a[5].num],xv3=val[x.a[4].num];
        if (x.a[2]==x.a[3] && x.a[3]==x.a[4]) xv1=val[x.a[2].num],xv2=val[x.a[5].num],xv3=val[x.a[1].num];
        if (x.a[3]==x.a[4] && x.a[4]==x.a[5]) xv1=val[x.a[3].num],xv2=val[x.a[2].num],xv3=val[x.a[1].num];
        if (y.a[1]==y.a[2] && y.a[2]==y.a[3]) yv1=val[y.a[1].num],yv2=val[y.a[5].num],yv3=val[y.a[4].num];
        if (y.a[2]==y.a[3] && y.a[3]==y.a[4]) yv1=val[y.a[2].num],yv2=val[y.a[5].num],yv3=val[y.a[1].num];
        if (y.a[3]==y.a[4] && y.a[4]==y.a[5]) yv1=val[y.a[3].num],yv2=val[y.a[2].num],yv3=val[y.a[1].num];
        V1=xv1*10000+xv2*100+xv3;V2=yv1*10000+yv2*100+yv3;
        if (V1>V2) return 1;if (V1<V2) return 0;
        return 2;
    }
    if (t1==7)
    {
        int xv1,xv2,xv3,yv1,yv2,yv3,V1,V2;
        if (x.a[1]==x.a[2] && x.a[3]==x.a[4]) xv1=val[x.a[3].num],xv2=val[x.a[1].num],xv3=val[x.a[5].num];
        if (x.a[1]==x.a[2] && x.a[4]==x.a[5]) xv1=val[x.a[4].num],xv2=val[x.a[1].num],xv3=val[x.a[3].num];
        if (x.a[2]==x.a[3] && x.a[4]==x.a[5]) xv1=val[x.a[4].num],xv2=val[x.a[2].num],xv3=val[x.a[1].num];
        if (y.a[1]==y.a[2] && y.a[3]==y.a[4]) yv1=val[y.a[3].num],yv2=val[y.a[1].num],yv3=val[y.a[5].num];
        if (y.a[1]==y.a[2] && y.a[4]==y.a[5]) yv1=val[y.a[4].num],yv2=val[y.a[1].num],yv3=val[y.a[3].num];
        if (y.a[2]==y.a[3] && y.a[4]==y.a[5]) yv1=val[y.a[4].num],yv2=val[y.a[2].num],yv3=val[y.a[1].num];
        V1=xv1*10000+xv2*100+xv3;V2=yv1*10000+yv2*100+yv3;
        if (V1>V2) return 1;if (V1<V2) return 0;
        return 2;
    }
    if (t1==8)
    {
        int xv1,xv2,xv3,xv4,yv1,yv2,yv3,yv4,V1,V2;
        if (x.a[1]==x.a[2]) xv1=val[x.a[1].num],xv2=val[x.a[5].num],xv3=val[x.a[4].num],xv4=val[x.a[3].num];
        if (x.a[2]==x.a[3]) xv1=val[x.a[2].num],xv2=val[x.a[5].num],xv3=val[x.a[4].num],xv4=val[x.a[1].num];
        if (x.a[3]==x.a[4]) xv1=val[x.a[3].num],xv2=val[x.a[5].num],xv3=val[x.a[2].num],xv4=val[x.a[1].num];
        if (x.a[4]==x.a[5]) xv1=val[x.a[4].num],xv2=val[x.a[3].num],xv3=val[x.a[2].num],xv4=val[x.a[1].num];
        if (y.a[1]==y.a[2]) yv1=val[y.a[1].num],yv2=val[y.a[5].num],yv3=val[y.a[4].num],yv4=val[y.a[3].num];
        if (y.a[2]==y.a[3]) yv1=val[y.a[2].num],yv2=val[y.a[5].num],yv3=val[y.a[4].num],yv4=val[y.a[1].num];
        if (y.a[3]==y.a[4]) yv1=val[y.a[3].num],yv2=val[y.a[5].num],yv3=val[y.a[2].num],yv4=val[y.a[1].num];
        if (y.a[4]==y.a[5]) yv1=val[y.a[4].num],yv2=val[y.a[3].num],yv3=val[y.a[2].num],yv4=val[y.a[1].num];
        V1=xv1*1000000+xv2*10000+xv3*100+xv4;V2=yv1*1000000+yv2*10000+yv3*100+yv4;
        if (V1>V2) return 1;if (V1<V2) return 0;
        return 2;
    }
}

inline void getmybest()
{
    bool exist=false;int Mask,i,pt;Hand cur;
    for (Mask=0;Mask<=(1<<7)-1;Mask++)
        if (__builtin_popcount(Mask)==5)
        {
            pt=0;
            for (i=1;i<=7;i++)
                if (Mask&(1<<(i-1))) cur.a[++pt]=seven[i];
            sort(cur.a+1,cur.a+6);
            if (!exist)
            {
                exist=true;
                mybest=cur;
            }
            else
            {
                int res=compare_hand(mybest,cur);
                if (!res) mybest=cur;
            }
        }
}

inline void getoppobest()
{
    bool exist=false;int Mask,i,pt;Hand cur;
    for (Mask=0;Mask<=(1<<7)-1;Mask++)
        if (__builtin_popcount(Mask)==5)
        {
            pt=0;
            for (i=1;i<=7;i++)
                if (Mask&(1<<(i-1))) cur.a[++pt]=seven[i];
            sort(cur.a+1,cur.a+6);
            if (!exist)
            {
                exist=true;
                oppobest=cur;
            }
            else
            {
                int res=compare_hand(oppobest,cur);
                if (!res) oppobest=cur;
            }
        }
}

inline Card getCard(int ind)
{
    Card res;
    int type=(ind-1)/13+1,num=ind-(type-1)*13;
    if (type==1) res.type='S';
    if (type==2) res.type='H';
    if (type==3) res.type='D';
    if (type==4) res.type='C';
    if (num==1) res.num='A';
    if (num==10) res.num='T';
    if (num==11) res.num='J';
    if (num==12) res.num='Q';
    if (num==13) res.num='K';
    if (2<=num && num<=9) res.num='0'+num;
    return res;
}

char s[10];

int main ()
{
    int i,j,k;
    for (i=2;i<=9;i++) val['0'+i]=i;
    val['T']=10;val['J']=11;val['Q']=12;val['K']=13;val['A']=14;
    while (scanf("%s",s+1)!=EOF && s[1]!='#')
    {
        my[1].type=s[1];my[1].num=s[2];
        scanf("%s",s+1);my[2].type=s[1];my[2].num=s[2];
        for (i=1;i<=2;i++)
        {
            scanf("%s",s+1);
            oppo[i].type=s[1];oppo[i].num=s[2];
        }
        for (i=1;i<=3;i++)
        {
            scanf("%s",s+1);
            all[i].type=s[1];all[i].num=s[2];
        }
        int cnt=0,wcnt=0;
        for (i=1;i<=51;i++)
            for (j=i+1;j<=52;j++)
            {
                other[1]=getCard(i);other[2]=getCard(j);
                if (Same(other[1]) || Same(other[2])) continue;
                cnt++;
                for (k=1;k<=2;k++) seven[k]=my[k];
                for (k=1;k<=3;k++) seven[2+k]=all[k];
                for (k=1;k<=2;k++) seven[5+k]=other[k];
                getmybest();
                for (k=1;k<=2;k++) seven[k]=oppo[k];
                getoppobest();
                int res=compare_hand(mybest,oppobest);
                if (res==1) wcnt++;
            }
        double ans=wcnt*1.0/cnt;
        printf("%.20lf\n",ans);
    }
    return 0;
}

No Fold'em Hold'em

12-24

DescriptionnnThe recent Texas Hold'em craze has spawned a bunch of on-line Poker sites. These sites tend to breed a group of poor players whose primary strategy is to never fold or throw away a hand. These players will always play and bet on every card on every hand no matter what the cost or what cards they have. You have decided to take advantage of these stupid players by developing your own poker site that allows you to always beat these players.nnThe way your site will work is: there are only two players in each game: you and your opponent (this is called a heads-up game). Each of the two players will get two “hole cards”; these cards are dealt face down so, presumably, only the player can see them. Four of the five community cards (cards shared by both players) will be dealt face up on the table. We will dispense with any betting for the purpose of this problem: it is irrelevant since each player will always call every bet right to the “river” (the fifth and final community card). You will always be seated at position 1, and your opponent at position 2. The program knows what seat you are sitting at and the hole cards for both players, therefore, it can compute all the cards that remain in the deck that will maximize the amount of money you would get playing the hand – folding is not an option. In the event there is no card that would allow you to win or tie the hand, you will be forced to take a loss on that hand (after all, it looks good if you lose sometimes).nnInputnnThe first line of input contains an integer N which is the number of data sets that follow (1 ≤ N ≤ 100) . Each data set consists of three lines. The first line of each dataset specifies your two hole cards. The second line is your opponent's hole cards. The third line is the four community cards. A card is specified by two characters: it's rank (A,2,3,4,5,6,7,8,9,T,J,Q,K) and it's suit (S,D,H,C) for Spades, Diamonds, Hearts, and Clubs respectively. For example, the Ace of Hearts would be AH, the Nine of Spades would be 9S. Within a line, there are no spaces or invalid characters. All input will be valid.nnOutputnnFor each data set, your program will output (on a new line) the data set number followed by a colon, followed by a space, and a list of card(s) that will maximize the amount of money you could get playing the hand. If no card will allow you to win or tie, just display ‘LOSER’ instead of the cards. Each card should be separated by a single space. Your program will display up to 15 cards on each output line. If more than one output line is required for a dataset, additional lines should be indented by exactly 3 spaces. Cards should be output in suit order (S,D,H,C) and rank order within each suit (Ace high).nnSample Inputnn3nJD3SnKH5SnKDAC2DQDn2S3Sn2C3Cn4D5DJHAHn4S7DnKHKDnAHADKSKCnSample Outputnn1: TS 3D 4D 5D 6D 7D 8D 9D TD AD TH TCn2: 4S 5S 6S 7S 8S 9S TS JS QS KS AS 2D 3D 6D 7Dn 8D 9D TD JD QD KD AD 2H 3H 4H 5H 6H 7H 8H 9Hn TH QH KH 4C 5C 6C 7C 8C 9C TC JC QC KC ACn3: LOSER

Know When to Hold 'em

08-12

DescriptionnnPoker is played with a standard deck of cards (no jokers). Every card has rank and suit. Possible card ranks in ascending order are: A,2,3,4,5,6,7,8,9,T,J,Q,K,A (Note that 'A' can be either high or low). Possible card suits in ascending order (the order of suits is for display purposes only and should not be used in determining hand or card value) are: Clubs (c), Diamonds (d), Hearts (h), Spades (s). This yields a total of 13 x 4 = 52 cards in a deck. nnPoker hands consist of five cards. The possible poker hands are listed below from best to worst. Examples for each type of hand are given in bold. nRoyal Flush -- Ace, King, Queen, Jack, Ten; all of the same suit. Ex: Ad Kd Qd Jd Td nStraight Flush -- Five cards with sequential rank, all of the same suit. Ace can be high or low, but not both. When there are two or more straight flushes, the straight flush with the highest ranked card wins. Ex: Ah 5h 4h 3h 2h nFour of a Kind -- Four cards of the same rank. If there are two or more hands that qualify, the hand with the higher ranking four of a kind wins. If there are two four of a kinds with the same rank, then the one with the high card outside the four of the kind wins. Ex: Kc 8s 8h 8d 8c nFull House -- Three cards of the same rank plus two cards sharing a different rank. When comparing full houses, the rank of the three cards determines which is higher. If the threes of a kind were equal, the rank of the pairs would decide. For example 9s 9h 9d 4d 4c beats As Ah 8s 8h 8d. Ex: Ts Th 3s 3h 3d nFlush -- Five cards of the same suit, any rank. When comparing two flushes, the highest card determines which is higher. If the highest cards are equal then the second highest cards are compared; if those are equal too, then the third highest cards, and so on. Ex: Kc 9c 8c 5c 2c nStraight -- Five cards with sequential rank, mixed suits. Ace can be high or low, but not both. When there are two straights, the straight with the highest ranked card wins. Ex: 9s 8h 7h 6c 5d nThree of a Kind -- Three cards with the same rank. The highest three of a kind rank wins. If both three of a kinds are the same rank, then the one with the highest cards outside the three of the kind wins. Ex: Ks 8h 6h 6d 6cnn"Texas Hold 'em" is a variation of poker that has gained popularity recently due to frequent national TV exposure. Each player receives two cards face down, known as "hole cards". Five cards, known as "the board", are then placed face up in the middle of the table. A player wins by making the best five-card poker hand possible using any combination of their two "hole cards" and the five cards on "the board". A useful skill for a Hold 'em player is to be able to tell the best possible hand an opponent might have. All the player knows are the five face up cards and his/her two hole cards. If an opponent can't make a better hand than the player, then the player knows to bet as much as possible. nnInputnnThe first line contains a single integer n indicating the number of data sets. nnEach data set is a line consisting of seven two-character strings separated from each other by single spaces. Each string represents a playing card. The first character will be the card's rank; the second character will be the card's suit. The first five cards represent "the board" while the last two represent the player's "hole cards". These cards are not in any specific order. nOutputnnFor each line of input, output the best five-card hand an opponent might make. If there are two or more cards of different suits that can be used to form the best hand (i.e., there is a tie), display those cards' suits as '*'. The cards should be listed in descending order based on rank first (Aces always considered high for display purposes) then suit (with '*' being lowest in the suit order). On the same line, output the name of the hand after the card list. Poker hand names: ROYAL FLUSH, STRAIGHT FLUSH, FOUR OF A KIND, FULL HOUSE, FLUSH, STRAIGHT, THREE OF A KIND.nSample Inputnn9n9c As 3h 8d 2s Jh Ahn6s 5h 5d 4s 4h 5s 5cnQc 3d Qd Qh 3h 3c QsnAh 2c 8d 6h Js 2d Asn8c 3d 2c Ad Tc Kc 4dnAs Js Kc Tc Qs 9s 8sn2d Kd Ad 6h 3d As AcnQc Qh As Qd Qs Ah Acn2d 5h 8s Jh Kd Ks AsnSample OutputnnAs 5* 4* 3h 2s STRAIGHTn6s 4s 4h 4d 4c FOUR OF A KINDnA* A* Qh Qd Qc FULL HOUSEnAh Ad Ac Js 8d THREE OF A KINDnAc Qc Tc 8c 2c FLUSHnAs Ks Qs Js Ts ROYAL FLUSHnAd 5d 4d 3d 2d STRAIGHT FLUSHnA* Qs Qh Qd Qc FOUR OF A KINDnKh Kd Kc Jh 8s THREE OF A KIND

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试