`
473687880
  • 浏览: 535126 次
文章分类
社区版块
存档分类
最新评论

The Psychic Poker Player UVA131

 
阅读更多


The Psychic Poker Player

In 5-card draw poker, a player is dealt a hand of five cards (which may be looked at). The player may then discard between zero and five of his or her cards and have them replaced by the same number of cards from the top of the deck (which is 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 see the cards in the deck and so must use probability to decide which cards to discard. In this problem, we imagine that the poker player is psychic and knows which cards are on top of the deck. 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 will consist of a series of lines, each containing the initial five cards in the hand then the first five cards on top of the deck. Each card is represented as a two-character code. The first character is the face-value (A=Ace, 2-9, T=10, J=Jack, Q=Queen, K=King) and the second character is the suit (C=Clubs, D=Diamonds, H=Hearts, S=Spades). Cards will be separated by single spaces. Each input line will be from a single valid deck, that is there will be no duplicate cards in 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 that is possible. Input is terminated by end of file.

Use the sample input and output as a guide. Note that the order of the cards in the player's hand is irrelevant, but the order of the cards in the deck is important because the discarded cards must be replaced from the top of the deck. Also note that examples of all types of hands appear in the sample output, with the hands shown in decreasing order of value.

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 TH
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 hand: 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: 6C 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-card

下面是从网上找的扑克牌规则:

1
Royal Flush 同花大顺又称皇家同花顺 它是所有德州扑克中的王牌,即使您经常玩扑克,也很少见到这样的牌。好比打高尔夫球一杆进洞一样。它是由T(10)到Ace的清一色同花组成。 Uva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>Player
<wbr></wbr> <wbr></wbr>
2
Straight Flush 同花顺 除了由最大同花所组成的同花大顺以外的同花组成的顺子。 Uva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>Player
<wbr></wbr> <wbr></wbr>
3
Four-of-a-Kind 四条 四张同样的牌+任意一张牌 。 Uva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>Player
<wbr></wbr> <wbr></wbr>
4

Full House 俘虏或船牌或葫芦 三条带一对,即三张同样的牌带两张同样的牌。如都是Full House,则先比较谁的三条大,如三条一样大,则比谁的两对大。如:

Uva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>Player
<wbr></wbr> <wbr></wbr>
5
Flush 五张同花 用五张同一花色但不相连的牌型组成,如都是五张同花,则谁的同花牌大谁赢。 Uva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>Player
<wbr></wbr> <wbr></wbr>
6
Straight 五张顺子 由五张相连但不同花色的牌组成,在连牌中,Ace是既可作最大也可以作最小的牌。 Uva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>Player
<wbr></wbr> <wbr></wbr>
7
Three-of-a-Kind 三条 即三张同样的牌。它有两种叫法,取决于一对牌是在您手中还是在桌上。一对在手中,桌上有一张,称之为“set”;v如手中有一张,桌上有一对,则称之为“Three of A Kind”。 Uva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>Player
<wbr></wbr> <wbr></wbr>
8
Two Pair 两对 由五张牌中的两对牌组成。如果都有两对,则先比大对,再比小对 。 Uva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>Player
<wbr></wbr> <wbr></wbr>
9
One Pair 一对 当不止一人有同样的一对牌时,则要比一对后面的牌,称之为“Kickers”。记住,德州扑克是挑选最好的五张牌去比。 Uva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>Player
<wbr></wbr> <wbr></wbr>
10
High Card 大牌 无以上任何牌型时,决定牌的大小 。 Uva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>PlayerUva<wbr><wbr>131<wbr>-<wbr>The<wbr>Psychic<wbr>Poker<wbr>Player

题意:从手上舍弃N张牌(0<=N<=5)从deck中顺序抽取N张牌,求所能达到的最大牌,我直接枚举模拟了。。。

太暴力了。。

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;

string str[9]={"straight-flush","four-of-a-kind","full-house","flush","straight","three-of-a-kind","two-pairs","one-pair","highest-card"};
string str1[5],str2[5];

bool cmp(string s1,string s2)
{
    return s1<s2;
}

bool straightflush(vector<string>st1)
{
    int tag1=1,tag2=1,tag=0,i;
    sort(st1.begin(),st1.end(),cmp);
    for(i=1;i<st1.size();i++)
    {
        if(st1[i][1]!=st1[i-1][1]||st1[i][0]!=(st1[i-1][0]+1))
        {
            tag1=0;
            break;
        }
    }
    if(st1[4][0]=='N'&&tag1==0)
    {
        tag=1;
        st1[4][0]='A';
        sort(st1.begin(),st1.end(),cmp);
        for(i=1;i<st1.size();i++)
        {
            if(st1[i][1]!=st1[i-1][1]||st1[i][0]!=(st1[i-1][0]+1))
            {
                tag2=0;
                break;
            }
        }
    }
    if(tag==0&&tag2==1) tag2=0;
    if(tag1||tag2) return true;
    else return false;
}

bool FourKind(vector<string>st1)
{
    int i,j;
    for(i=0;i<st1.size();i++)
    {
        int k=0;
        for(j=0;j<st1.size();j++)
        {
            if(st1[i][0]==st1[j][0])
            {
                k++;
            }
        }
        if(k==4) return true;
    }
    return false;
}

bool Full(vector<string>st1)
{
    int h[5],tag1=0,tag2=0;
    int i,j;
    for(i=0;i<st1.size();i++)
    {
        h[i]=0;
        for(j=0;j<st1.size();j++)
        {
            if(st1[i][0]==st1[j][0])
            {
                h[i]++;
            }
        }
    }
    for(i=0;i<5;i++)
    {
        if(h[i]==3) tag1++;
        else if(h[i]==2) tag2++;
    }
    if(tag1==3&&tag2==2) return true;
    else return false;
}

bool Flush(vector<string> st1)
{
    int tag=1,i;
    for(i=1;i<st1.size();i++)
    {
        if(st1[i][1]!=st1[i-1][1])
        {
            tag=0;
        }
    }
    if(tag) return true;
    else return false;
}

bool Straight(vector<string> st1)
{
    int tag1=1,tag2=1,tag=0,i;
    sort(st1.begin(),st1.end(),cmp);
    for(i=1;i<st1.size();i++)
    {
        if(st1[i][0]!=(st1[i-1][0]+1))
        {
            tag1=0;
            break;
        }
    }
    if(tag1==0&&st1[4][0]=='N')
    {
        tag=1;
        st1[4][0]='A';
        sort(st1.begin(),st1.end(),cmp);
        for(i=1;i<st1.size();i++)
        {
            if(st1[i][0]!=(st1[i-1][0]+1))
            {
                tag2=0;
                break;
            }
        }
    }
    if(tag==0&&tag2==1) tag2=0;
    if(tag1||tag2) return true;
    else return false;
}

bool Three(vector<string> st1)
{
    int i,j;
    for(i=0;i<st1.size();i++)
    {
        int k=0;
        for(j=0;j<st1.size();j++)
        {
            if(st1[i][0]==st1[j][0])
            {
                k++;
            }
        }
        if(k==3) return true;
    }
    return false;
}

bool twopair(vector<string> st1)
{
    int tag=0,h[5];
    int i,j;
    for(i=0;i<st1.size();i++)
    {
        h[i]=0;
        for(j=0;j<st1.size();j++)
        {
            if(st1[i][0]==st1[j][0])
            {
                h[i]++;
            }
        }
    }
    for(i=0;i<5;i++)
    {
        if(h[i]==2) tag++;
    }
    if(tag==4) return true;
    else return false;
}

bool onepair(vector<string> st1)
{
    int i,j;
    for(i=0;i<st1.size();i++)
    {
        int k=0;
        for(j=0;j<st1.size();j++)
        {
            if(st1[i][0]==st1[j][0])
            {
                k++;
            }
        }
        if(k==2) return true;
    }
    return false;
}

int judge(vector<string> st1)
{
    int i;
    for(i=0;i<st1.size();i++)
    {
        if(st1[i][0]>='2'&&st1[i][0]<='9') st1[i][0]='A'+(st1[i][0]-'1');
        else if(st1[i][0]=='T') st1[i][0]='J';
        else if(st1[i][0]=='J') st1[i][0]='K';
        else if(st1[i][0]=='Q') st1[i][0]='L';
        else if(st1[i][0]=='K') st1[i][0]='M';
        else if(st1[i][0]=='A') st1[i][0]='N';
    }
    if(straightflush(st1)) return 0;
    else if(FourKind(st1)) return 1;
    else if(Full(st1)) return 2;
    else if(Flush(st1)) return 3;
    else if(Straight(st1)) return 4;
    else if(Three(st1)) return 5;
    else if(twopair(st1)) return 6;
    else if(onepair(st1)) return 7;
    else return 8;
}

int main()
{
    string s;
    while(cin>>s)
    {
        str1[0]=s;
        int i,j,k,l;
        for(i=1;i<5;i++)
            cin>>str1[i];
        for(i=0;i<5;i++)
            cin>>str2[i];
        int t=9;
        for(i=0;i<=5;i++)
        {
            vector<string> st;
            string s1;
            for(k=0;k<i;k++)
            {
                s1=s1+'0';
            }
            for(k=0;k<5-i;k++)
            {
                s1=s1+'1';
            }
            //cout<<s1<<endl;
            for(j=0;j<i;j++)
            {
                st.push_back(str2[j]);
            }
            for(k=0;k<5;k++)
            {
                if(s1[k]=='1') st.push_back(str1[k]);
            }
            if(judge(st)<t) t=judge(st);
            while(next_permutation(s1.begin(),s1.end()))
            {
                st.clear();
                for(j=0;j<i;j++)
                {
                    st.push_back(str2[j]);
                }
                for(k=0;k<5;k++)
                {
                    if(s1[k]=='1') st.push_back(str1[k]);
                }
                if(judge(st)<t) t=judge(st);
                //cout<<s1<<endl;
            }
        }
        //cout<<t<<endl;
        cout<<"Hand: ";
        for(i=0;i<5;i++)
            cout<<str1[i]<<" ";
        cout<<"Deck: ";
        for(i=0;i<5;i++)
            cout<<str2[i]<<" ";
        cout<<"Best hand: ";
        cout<<str[t]<<endl;
    }
    return 0;
}

分享到:
评论

相关推荐

    The-Psychic-Poker-Player:解决方案

    The-Psychic-Poker-Player-master这个文件名暗示了项目可能使用了Git进行版本控制,这有助于团队协作和代码版本管理。此外,可能还有Maven或Gradle这样的构建工具,用于自动化构建、依赖管理和打包。 总的来说,...

    cpp-Psychic基于psyc的ARM板的深度学习库

    《cpp-Psychic:基于PsyC的ARM板深度学习库解析》 在现代计算机科学领域,深度学习作为机器学习的一个分支,已经在图像识别、自然语言处理、语音识别等诸多领域取得了显著成果。随着硬件技术的发展,尤其是嵌入式...

    Eye of the Psychic-Paranormal Investigations-crx插件

    语言:English 进入令人兴奋的令人兴奋的全球调查世界和精神审查 随着互联网的增长,人们提出问题的人数也是如此。我们不再绑在等待书籍,以便获得我们正在寻找的答案。它已成为一个伟大的教育工具和一种启发别人的...

    Python库 | psychic_disco-0.10.0.tar.gz

    《Python库:深入理解psychic_disco-0.10.0》 在Python的世界里,库是开发者的重要工具,它们提供了丰富的功能,使得代码编写更加高效和便捷。本文将聚焦于一个名为"psychic_disco"的Python库,详细探讨其在0.10.0...

    psychic-ui:OpenGL UI库

    "psychic-ui" 是一个基于 OpenGL 的用户界面(UI)库,意味着它主要用于创建图形用户界面,并且利用 OpenGL 这个强大的图形处理库来渲染和交互。"OpenGL UI库" 进一步确认了这个项目的核心功能是为开发者提供一套...

    Psychic-Game:猜猜计算机在想什么!

    在这个名为"Psychic-Game"的独特项目中,我们有机会体验一种别出心裁的互动游戏,它巧妙地融合了人类的直觉与计算机的逻辑。这个游戏的核心概念是让玩家尝试猜测计算机随机生成的数字,从而挑战我们的思维能力和计算...

    Psychics:适用于Paper的Minecraft Psychic插件

    心理 소개 发布。 용법개발개발 编译 ./gradlew构建 插件= ./psychics-common/build/libs/Psychics.jar 能力= ./psychics-abilities/build/libs/GroupName.AbilityName.jar 依赖插件 ... 후PaperMC 1.16.3구동하세요...

    psychic-disco

    测试 01.访问日志分析 运行环境: Linux(Ubuntu优先) 先决条件: 卷曲 q 操作说明: 从ftp://ita.ee.lbl.gov/traces/NASA_access_log_Aug95.gz下载日志文件 解压下载的文件并将其放入question1文件夹 ...

    psychic-sniffle:https

    psychic-sniffle:https

    Master Psychic Online-crx插件

    通过Master Psychic Rachel在线获得免费或付费的心理阅读 与Internet排名最高的在线心理学家之一,Master Psychic Rachel一起获得免费或付费的心理学读物。 * MasterPsychicOnline.com是您免费心理阅读的第一来源。 ...

    Psychic Messenger 3 Free Psychic Answers-crx插件

    Psychic Messenger 3免费通灵问答 获得3个免费的心理答案,当您可以获得其他免费的心理答案时,会收到新优惠的通知。 如果您有需要心理答案的问题,或者想知道将来会发生什么,这是给您的! 关系答案爱情生活答案...

    Psychic-Game:Javascript作业

    "Psychic-Game"是一个基于JavaScript的项目,旨在帮助学习者通过实际操作来深化对JavaScript的理解。这个游戏,我们可以称之为“通灵游戏”,其设计不仅有趣,更富有教育意义,它将引导我们走进JavaScript的核心概念...

    psychic

    精神sharkey告诉我16岁的时候,如果我多呼吸,直到我头昏眼花,我就不再通灵了,这与他的生意有关。 因为他的生意全是通灵的,这就是他的心灵感应。 我想知道我想告诉中央情报局...帮助我。 这种鲨鱼是疯狂的。...

    Psychic Awakening Software-crx插件

    此Psychic Awakening软件使用模式识别(您的大脑功能)在100%随机静态范围内找到潜意识图像(在右侧启用Adobe Flash)。 有了开放思想,您也可以在此计算机屏幕和网站上看到“心理思想图像”。 显示“静态”后,您...

    掌握心理在线「Master Psychic Online」-crx插件

    与Internet排名最高的在线心理学家之一,Master Psychic Rachel一起获得免费或付费的心理学读物。 * MasterPsychicOnline.com是您免费心理阅读的第一来源。 *首次客户可以每月支付1倍费用,并获得免费的答案。 * Vip...

    Psychic-Game:JavaScript分配

    答:这是一个JavaScript项目,其中包含一个名为Psychic Game的游戏。 它允许玩家尝试猜测通灵者在想什么字母。 问:为什么这个项目有用? 答:这个项目很有用,因为它可以帮助人们获得乐趣。 问:如何开始这个...

    psychic-batman

    "psychic-batman"项目是一个基于Django框架构建的简单消息网站,旨在为开发者提供一个自我娱乐的平台。这个项目可能包含与Web开发、Python编程、Django框架以及JavaScript相关的技术知识。以下是对这些技术点的详细...

    matlab距离矩阵代码-PSYCHIC:使用Hi-C数据查找推定的增强子的代码

    matlab距离矩阵代码精神 使用Hi-C数据查找推定的增强子的代码 用法 python htad-​​chain.py 要运行该示例,请使用repo目录中的python htad-chain.py examples/himr90.chr20.conf 。...Hi-C文件的res分辨率,以基为...

Global site tag (gtag.js) - Google Analytics