UVA 131 The Psychic Poker Player

UVA-131

题意:给出 5 张手牌和 5 张备用牌。可以任意丢弃手上的 k 张牌,并从备用牌上方抽 k 张补充。求手上能达到的最大牌面。
解题思路:
首先要搞清楚牌面的大小顺序。
同花顺(AKQJ10,花色相同就行)>四条(四张相同的牌,炸弹 = =) > 福尔豪斯 (aaabb的牌型) > 同花(5张花色相同) > 顺子 (连续,无视花色。A可以当1也可以当14)> 三条 (aaabc的牌型)> 两对 >一对 > 单张大牌。
DFS去枚举扔掉哪些,记住可以取到的最大的牌面。

/*************************************************************************
    > File Name: UVA-131.cpp
    > Author: Narsh
    > 
    > Created Time: 2016年07月26日 星期二 14时46分37秒
 ************************************************************************/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const string t[9]={"straight-flush","four-of-a-kind",  
    "full-house","flush","straight","three-of-a-kind",  
    "two-pairs","one-pair","highest-card"};
int map[6][20],now,ans,num[20],col[6],l;
string hand[10],deck[10];
int value(char ch) {
    if (ch == 'T' ) return 10;
    if (ch == 'J' ) return 11;
    if (ch == 'Q' ) return 12;
    if (ch == 'K' ) return 13;
    if (ch == 'A' ) return 1;
    return ch-'0';
}
int color(char ch) {
    if ('S' == ch) return 1;
    if (ch == 'H') return 2;
    if (ch == 'D') return 3;
    if (ch == 'C') return 4;
}
int test() {
    int x=0,y=0;
    for (int i = 1; i <= 4; i++)
        if (map[i][1] && map[i][10] && map[i][11] && map[i][12] && map[i][13]) return 0;
    for (int i = 1; i <= 13; i++)
        if (num[i] == 4) return 1;
    for (int i = 1; i <= 13; i++) {
        if (num[i] == 2) x++;
        if (num[i] == 3) y++;
    }
    if (x && y) return 2;
    if (!x && y) return 5;
    if (x == 2) return 6;
    if (x) return 7;
    for (int i = 1; i <= 4; i++)
        if (col[i] == 5) return 3;
    x=0;
    for (int i = 1; i <= 13; i++)
        if (num[i] != 0) {
            x++;
            if (x == 5) return 4;
        }else x=0;
    if (x == 4 && num[1]) return 4;
    return 8;
}
void dfs(int i) {
    if (i > 5) {
        int x=test();
        if (x < ans) ans=x;
        return ;
    }
    int x,y;
    x=value(hand[i][0]);
    y=color(hand[i][1]);
    map[y][x] ++;
    num[x] ++;
    col[y] ++;
    dfs(i+1);
    num[x]--;
    col[y]--;
    map[y][x] --;
    x=value(deck[l][0]);
    y=color(deck[l][1]);
    map[y][x]++;
    num[x]++;
    col[y]++;
    l++;
    dfs(i+1);
    num[x]--;
    col[y]--;
    map[y][x]--;
    l--;
}
int main() {
    while (cin>>hand[1]){
        printf("Hand: ");
        cout<<hand[1]<<" ";
        for (int i = 2; i <= 5; i++) {
            cin>>hand[i];
            cout<<hand[i]<<" ";
        }
        printf("Deck: ");
        for (int i = 1; i <= 5; i++) {
            cin>>deck[i];
            cout<<deck[i]<<" ";
        }
        memset(map,0,sizeof(map));
        ans=20;
        l=1;
        dfs(1);
        printf("Best hand: ");
        cout<<t[ans]<<endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值