UVA131 HDU1629 The Psychic Poker Player【暴力】

The Psychic Poker Player
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 255 Accepted Submission(s): 49

Problem Description
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
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

Source
uva

问题链接UVA131 HDU1629 The Psychic Poker Player
问题简述:(略)
问题分析
????德州扑克牌问题,判定手牌最佳的牌。
????10张牌中任意取5张,从中找出最佳牌点。
straight-flush  同花顺
four-of-a-kind   炸弹
full-house    满堂红(三张同点牌加上一对)
flush     同花
straight    顺子(注意A即可接2也可以接K)
three-of-a-kind 三张相同的牌
two-pairs    两对对子
one-pair    一对对子
highest-card 单张最大
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++程序如下:

/* UVA131 HDU1629 The Psychic Poker Player */

#include <bits/stdc++.h>

using namespace std;

const int N = 10;
const int M = 5;
string s[N], a[M];
string bh[] = {     // Best Hand
     "straight-flush"
    , "four-of-a-kind"
    , "full-house"
    , "flush"
    , "straight"
    , "three-of-a-kind"
    , "two-pairs"
    , "one-pair"
    , "highest-card"
};

int b[5], c[5];

int convert[128];
void init()
{
    for(int i = 2; i <= 9; i++)
        convert['0' + i] = i;
    convert['T'] = 10;
    convert['J'] = 11;
    convert['Q'] = 12;
    convert['K'] = 13;
    convert['A'] = 14;

    convert['C'] = 1;       // 梅花
    convert['D'] = 2;       // 方片
    convert['H'] = 3;       // 红桃
    convert['S'] = 4;       // 黑桃
}

int solve()
{
    int flush, straight, i, j;        // 同花:flush,顺子:straight

    for (i = 0; i < M; i++) {
        b[i] = convert[(int)a[i][0]];
        c[i] = convert[(int)a[i][1]];
    }

    // 整理牌:排序
    for (i = 0; i < M - 1; i++)
        for (j = i + 1; j < M; j++)
            if (b[i] > b[j]) {
                swap(b[i], b[j]);
                swap(c[i], c[j]);
            } else if (b[i] == b[j] && c[i] > c[j])
                swap(c[i], c[j]);

    // 判定同花
    for (flush = 1, i = 0; i < M - 1; i++)
        if (c[i] != c[i + 1]) {
            flush = 0;
            break;
        }

    // 判定顺子
    for (straight = 1, i = 0; i < M - 1; i++)
        if (b[i] + 1 != b[i + 1]) {
            if (i == 3 && b[i + 1] == 14 && b[0] == 2)
                ;
            else {
                straight = 0;
                break;
            }
        }

    if (flush && straight) return 0;
    if (b[1] == b[3] && (b[1] == b[0] || b[3] == b[4])) return 1;
    if (b[0] == b[1] && b[2] == b[4]) return 2;
    if (b[0] == b[2] && b[3] == b[4]) return 2;
    if (flush) return 3;
    if (straight) return 4;
    if (b[0] == b[2] || b[1] == b[3] || b[2] == b[4]) return 5;
    if (b[0] == b[1] && (b[2] == b[3] || b[3] == b[4])) return 6;
    if (b[1] == b[2] && b[3] == b[4]) return 6;
    if (b[0] == b[1] || b[1] == b[2] || b[2] == b[3] || b[3] == b[4]) return 7;
    return 8;
}

int main()
{
    init();

    int ans, i, j, k;
    while (cin >> s[0]) {
        for (i = 1; i < N; i++)
            cin >> s[i];

        // 暴力搜索:10中取5处理,2^5=32
        for (ans = 8, i = 0; i < 32; i++) {
            for (j = 0, k = 0; j < M; j++)
                if (((i >> j) & 1) == 1) a[k++] = s[j];
            for (j = M; j < N && k < M; j++) a[k++] = s[j];
            ans = min(ans, solve());
        }

        // 输出结果
        cout << "Hand: " ;
        for (i = 0; i < M; i++) cout << s[i] << " ";
        cout << "Deck: " ;
        for (i = M; i < N; i++) cout << s[i] << " ";
        cout << "Best hand: " << bh[ans] << endl;
    }

    return 0;
}

原文地址:https://www.cnblogs.com/tigerisland45/p/10459725.html

时间: 2024-10-19 09:04:54

UVA131 HDU1629 The Psychic Poker Player【暴力】的相关文章

uva 131 The Psychic Poker Player (暴力枚举)

uva 131 The Psychic Poker Player  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 sam

UVa 131 - The Psychic Poker Player

题目:手里有五张牌,桌上有一堆牌(五张),你可以弃掉手中的k张牌,然后从牌堆中取最上面的k个. 比较规则如下:(按优先级排序) 1.straight-flush:同花顺,牌面为T(10) - A,这里不论花色是否相同: 2.four-of-a-kind:四条,牌面有4个相同的值: 3.full-house:船牌,牌面有3个相同值,剩下2个也相同值: 4.flush:同花,五张牌的花色相同,不是同花顺: 5.straight:顺子,五张牌的值连续,A可以作为1也可以作为14: 6.three-of

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

Storyboard 全解析

XCode 4.3.2 新功能 - Storyboard 最近开始比较有空在玩 XCode 4.3.2,赫然发现它多了个 Storyboard 的东东. Storyboard 这个东西一般来说是在做创意发想的时候,用来将自己的想的一些故事情节画成像是连环漫画一样,想不到 Apple 把它用在这里,真是佩服... 好吧,不废话,先来说说这个 Storyboard 带来什么改变? 在这个版本前,我们在设计画面的时候都是用 interface builder 产生一个 xib 档,然后在 code 要

IOS开发之Storyboard应用

制作一个Tab类型的应用 制作一个表格视图 原型表格单元 设计自定义的原型单元格 为原型单元格设置子类 故事版(Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果,我贴上本教程所完成的Storyboard的截图:   现在,你就可以清楚的看到这个应用究竟是干些什么的,也可以清楚的看到其中的各种关系,这就是Storyboard的强大之处了.如果你要制作一个页面很 多很复杂的App,Storyboard可以帮助你解决写很多重复的跳

在iOS 7中使用storyboard(part 1)

原文:Storyboards Tutorial in iOS 7: Part 1 感谢翻译小组成员heartasice热心翻译.如果您有不错的原创或译文,欢迎提交给我们,更欢迎其他朋友加入我们的翻译小组(联系qq:2408167315). ========================================================================================== Storyboard是一项令人兴奋的功能,在iOS5中首次推出,在开发app的

iOS Storyboard 的基本用法

(Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果,我贴上本教程所完成的Storyboard的截图:  现 在,你就可以清楚的看到这个应用究竟是干些什么的,也可以清楚的看到其中的各种关系,这就是Storyboard的强大之处了.如果你要制作一个页面很多 很复杂的App,Storyboard可以帮助你解决写很多重复的跳转方法的麻烦,节省很多时间,以便你能够完全的专注于核心功能的实现上. 开始 首先启动Xcode,新建一个工程,

最新iOS 6 in Xcode4.5新特性——Storyboard和属性自动绑定

最新iOS 6 in Xcode4.5新特性编程之二(上)——Storyboard和属性自动绑定 从Xcode 4.3开始,Storyboard 就是iOS 5和iOS 6中令人兴奋的一个新特性,他将为你在创建用户界面上节省很多时间. 那么究竟什么是Storyboard呢?我将用一幅图片来向你展示: 下面这个就是本实例中即将用到的Storyboard. 关于故事板编程,我在“最新Xcode 4.3.2 下使用Storyboard和ARC开发iPhone4程序 03——Storyboard类及使用

iOS Storyboard全解析(转)

来源:http://iaiai.iteye.com/blog/1493956 Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果,我贴上本教程所完成的Storyboard的截图:  现 在,你就可以清楚的看到这个应用究竟是干些什么的,也可以清楚的看到其中的各种关系,这就是Storyboard的强大之处了.如果你要制作一个页面很多 很复杂的App,Storyboard可以帮助你解决写很多重复的跳转方法的麻烦,节省很多时间,以便你