uva-131 - The Psychic Poker Player

深入理解EtherCAT状态机:从IGH代码看伺服电机如何从‘上电’到‘使能’ 本文深入解析EtherCAT状态机的工作原理,重点探讨伺服电机从'上电'到'使能'的状态转换过程。通过分析状态字(Status Word)和控制字(Control Word)的交互机制,结合IGH代码实例,揭示DS402状态机的核心逻辑,帮助工程师解决60%以上的伺服控制问题,提升EtherCAT网络调试效率。 阅读详情



 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


题意是给你手上五张牌,桌子上五张牌。你有一次机会可以舍弃手上任意k张牌,并从桌子上顶部开始拿k张牌,输出手上的牌和桌子上的牌和你能得到的最大组合

直接枚举一遍五张牌的状态然后舍弃和抽取,找出最大的组合。用5位二进制数表示五张牌的状态,1代表丢弃,0代表保留,用变量i从0-31表示总共32种状态

#include <iostream>
#include <algorithm>
using namespace std;

//枚举常量,按照牌的大小,从大到小
enum BestHand{straight_flushs,four_of_a_kind,full_house,flushs,straight,
        three_of_a_kind, two_pairs, one_pair};

string str[8] = {"straight-flush","four-of-a-kind","full-house","flush","straight",
        "three-of-a-kind", "two-pairs", "one-pair"};


struct c   //每张牌的数据,数值大小和花色
{
    int value;
    char suit;
};

int getValue(char ch) //牌的大小2-A,转换成由数字1-13表示,便于比较和排序
{
    switch(ch){
    case 'A':
        return 13;
    case 'T':
        return 9;
    case 'J':
        return 10;
    case 'Q':
        return 11;
    case 'K':
        return 12;
    default:
        return 1+ch-'2';
    }
}

c deck[5];
c hand[5];
c cp[5];

int cmp(const c & a, const c &b) //牌的排序方式,用作sort函数的参数
{
    return a.value < b.value;
}

//牌判断前都是按大小从小到大排好序了

int isSAF()     //判断,同花、顺子、同花顺
{
    int s = 1, f = 1;  //s(straight)代表是否顺子,f(flush)代表同花

    //判断是否为顺子,因A代表的是13,所以第二个条件是对于A 2 3 4 5特判
    for(int i = 0; i < 4; i++)
     if(cp[i+1].value - cp[i].value != 1 && !(i==3 && cp[i].value==4 && cp[i+1].value == 13)){
        s = 0;
        break;
    }

    for(int i = 1; i < 5; i++)
    if(cp[i].suit != cp[0].suit){
        f = 0;
        break;
    }

    if(s && f)
        return straight_flushs;
    else if(f)
        return flushs;
    else if(s)
        return straight;
    else
        return 100; //什么都没有返回一个不可能的值,取大的



}

int isFAK() //判断炸
{
    for(int i = 1; i < 4; i++){
        if(cp[i].value != cp[0].value)
            break;
        if(i == 3) return four_of_a_kind;
    }

    for(int i = 3; i >= 1; i--){
        if(cp[i].value != cp[4].value)
            break;
        if(i == 1) return four_of_a_kind;
    }

    return 100;
}


int isTTO()//判断葫芦,三条,两对,一对
{
    int three = 0, pairs = 0;

    for(int i = 0; i < 3; i++)
        if(cp[i].value == cp[i+1].value && cp[i+1].value == cp[i+2].value)
            three = 1;
    //判断对的时候注意如果是三条就不能算对了
    for(int i = 0; i < 4; i++)
        if(cp[i].value == cp[i+1].value && cp[i+1].value != cp[i+2].value && (!i || (cp[i-1].value != cp[i].value)))
        pairs++;

    if(three && pairs)
        return full_house;
    else if(three)
        return three_of_a_kind;
    else if(pairs == 2)
        return two_pairs;
    else if(pairs)
        return one_pair;
    else
        return 100;

}



int main()
{
    char a, b;
    while(cin >> a >> b){
    cout << "Hand: ";
    for(int i = 0; i < 5; i++){
            if(i)
            cin >> a >> b;
            hand[i].value = getValue(a);
            hand[i].suit = b;
            cout << a << b << " ";
    }

    cout << "Deck: ";
    for(int i = 0; i < 5; i++){
            cin >> a >> b;
            deck[i].value = getValue(a);
            deck[i].suit = b;
            cout << a << b << " ";
    }

    int ans = 100;
    cout << "Best hand: ";
    for(int i = 0; i < 32; i++){ //用5个二进制数表示手上牌的状态,1代表丢弃换牌,0表示不换
        int used = 0;   //表示换了多少张牌,从左边开始换(也就deck上的top)
        for(int j = 0; j < 5; j++) cp[j] = hand[j];
        for(int t = 0; t < 5; t++){
            if((i>>t)&1) cp[t] = deck[used++];
        }

        sort(cp, cp+5, cmp); //将牌从小排到大

        ans = min(ans, isSAF());
        ans = min(ans, isFAK());
        ans = min(ans, isTTO());
    }



    if(ans == 100) //什么都没有输出highest-card
        cout <<"highest-card\n";
    else
        cout << str[ans] << endl;
    }
    return 0;
}


蓝凌EIS智慧协同平台frm_form_upload.aspx接口存在任意文件上传漏洞 阅读详情

相关推荐

Ardupilot姿态控制详解(完结篇)

本文主要是对过去写的一些APM中姿态控制流程及函数博文的汇总。 按照之前写的博文以及个人认为的学习顺序,给出APM姿态控制器的学习顺序如下: APM姿态旋转理论基础 Ardupilot姿态控制器 PID控制流程(整定后的P控制器) 详解APM的开方控制器sqrt_controller Ardupilot前馈及平滑函数input_euler_angle_roll_pitch_yaw解析 Ardupilot倾转分离函数thrust_heading_rotation_angles Ardupilot四元数姿态控制

moumde的博客 7024

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 ha

小G的ACM之路 1085

最大似然估计、梯度下降、EM算法、坐标上升

主要讲解的是机器学习中参数学习算法之间的区别,以及应用的场景。 最大似然估计: 其中目标函数是对数似然函数。为了求目标函数取最大值时的theta。有两个关机键步骤,第一个是对目标函数进行求导,第二个是另导数等于0,求解后直接得到最优theta。两个步骤缺一不可。 梯度下降: 对目标函数进行求导,利用导函数提供的梯度信息,使参数往梯度下降最快的方向移动一小步,来更新参数。为什

tzl2093的博客 5141

131 - The Psychic Poker Player(直接枚举)

题目:131 - The Psychic Poker Player 题目大意:刚开始我一点都不懂题目要我们做什么,后来看了别人的题解,发现原来是打某种类型的纸牌,手上有5张牌,桌上也五张牌,这个人可艺从手中丢弃某些牌,从轴上摸去相等数量的牌,桌上的牌是有顺序的,然后问手上最好的牌是什么。 解题思路:直接枚举丢牌和摸牌的情况,一共有2的5次方种,这里我用了位运算,用一个数来代替舍

801

【BLE】HID设备开发实战:从自拍杆到复合设备的蓝牙控制方案

本文深入解析了BLE HID(低功耗蓝牙人机接口设备)的开发实战,从蓝牙自拍杆的工作原理切入,详细阐述了HID Report Map的设计与实现。通过拆解自拍杆、键盘、鼠标等案例,指导开发者如何利用BLE的低功耗与即插即用特性,构建从单一功能到键盘鼠标复合设备的完整蓝牙控制方案。

weixin_29159613的博客 464

UVaOJ131---The Psychic Poker Player

131 - The Psychic Poker Player Time limit: 3.000 seconds 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

c随遇er安的专栏 702

【大数据技术干货】(还不懂数仓,数据中心?看这一篇就够了!)在实际的开发生产中,让你了解企业级数据中心整体架构(DB+ETL+ODS+DW+DM)的各个层次的过程详解,数据联系及功能区分

一 企业级数据中心架构 数据仓库的整体架构,各个系统的元数据通过ETL同步到操作性数据仓库ODS中,对ODS数据进行面向主题域建模形成DW(数据仓库),DM是针对某一个业务领域建立模型,具体用户(决策层)查看DM生成的报表。 二 DB 三 ETL(Extract-Transform-Load) ETL是将业务系统的数据经过抽取、清洗转换之后加载到数据仓库的过程,目的是将企业中的分散、零乱、标准不统一的数据整合到一起,为企业的决策提供分析依据。 ETL是BI项目重要的一个环节。 通常情况下,在BI项目中ET

liuchunhang的博客 1288

uva 131 The Psychic Poker Player(暴力枚举+德州扑克)

uva 131 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

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 1890

【总目录】AUTOSAR精进之路专栏介绍及内容目录持续更新...

本专栏系统讲解AUTOSAR汽车电子开发技术,包含Eth/OS/Can/Lin等协议栈、MCAL驱动、功能安全等核心模块。内容基于实际项目经验,从概念原理到工程配置、特殊需求实现及问题排查进行深入剖析。重点涵盖TC3xx芯片平台开发、多核OS、网络管理、存储协议栈等难点问题,提供100+篇原创技术文章。专栏采用付费模式,保证内容完整性和持续更新,并提供专业答疑服务。适合汽车电子工程师系统学习AUTOSAR开发技术。

qq_36056498的博客 6505

uniapp - 解决App端报错reportJSException >>>> exception function:createInstanceContext, exception:white sc

uni-app,安卓Android,苹果ios,安卓app端,苹果App端,uniapp苹果安卓app,uniApp报错,reportJSException>>>>exceptionfunction:createInstanceContext,exception:whitescreencausecreateinstanceContextfailed,运行自定义基座时白屏,uniapp项目运行白屏reportJSException,检查没问题依旧报错,第三方库插件,组件,uniapp打包调试

🏆 前端领域优质创作者 1万+

UVa 131 The Psychic Poker Player

本文介绍了一个扑克牌游戏问题,玩家初始获得5张手牌,可通过丢弃0-5张牌并用牌堆顶部的牌替换来优化牌型。题目假设玩家能预知牌堆顶部的5张牌。解题思路是枚举所有可能的换牌方案(共32种),并对每种方案评估牌型价值。关键点包括:换牌规则、枚举策略(暴力搜索)、牌型判断顺序(从同花顺到高牌共9种)。代码实现通过回溯法生成所有换牌组合,调用牌型判断函数确定最优解。该算法能高效找到最佳换牌策略,使最终手牌价值最大化。

寂静山林 688

C# MVVM的“核武器”:CommunityToolkit.Mvvm的RelayCommand实战全解

你默默打开VS:“该用RelayCommand的‘量子纠缠’魔法了!用户点击按钮无响应,调试器显示命令未绑定,但代码看起来完美无缺。“我的MVVM应用?那可是能穿越线程的命令量子计算机!异步操作阻塞了UI线程,用户界面变成“加载中”死循环。:UI与业务逻辑通过命令“量子隧道”解耦。:所有长时间操作自动进入“量子跃迁”模式。:携带任意上下文的“量子信封”传递。:命令可用性随数据变化实时同步。

java专栏 663

uva 131 The Psychic Poker Player

思路挺简单的,就是判断手牌的类型比较麻烦一点,核心思想是枚举手牌子集,然后把桌上的牌的上面的某几张牌和手牌子集中的牌凑足5张,所有的情况里面最优的组合就是最后的答案,注意子集为空集的时候的特殊情况。 #include #include #include struct node { int value; char color; }; bool operator > (struct

皓首不倦 不负少年 744

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

uva 131 - The Psychic Poker Player

参考题解  原题  子集生成的问题。用增量构造法。需要先弄清楚规则。特殊的顺子有两种,TJQKA和A2345。 #include #include #include using namespace std; const int maxn=15; char *sf="A23456789TJQK"; char *su="CDHS"; char str[9][20]={"straight-f

LeanCloud-lzwjava 969

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

UVA 131 The Psychic Poker Player

UVA 131 The Psychic Poker Player题目大意:手牌五张 排堆五张,超能力者可以看到这10张牌,可以弃掉x张牌摸x张牌,问能凑出的最大的牌 比较规则 比较规则如下:(按优先级排序)1.straight-flush:同花顺,牌面为T(10) - A2.four-of-a-kind:四条,牌面有4个相同的值;3.full-house:牌面有3个相同值,剩下2个也相同值;4.

ZeroLH00的博客 434

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

UVa 131 - The Psychic Poker Player

一手牌(规则请见:http://dpk888.com/school/discussions/%E4%B8%80%E6%89%8B%E7%89%8C%E7%9A%84%E7%89%8C%E5%9E%8B-poker-hands#per_page=10),枚举 + 模拟,关键是明白其桌子上的牌相当于一个栈,只有丢掉手里相应数量的牌才可以从栈中依次抽出相应数量的牌来维持手里始终有五张牌,依此枚举。

GooMaple 725

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 p...

海岛Blog 725

UVA 131 The Psychic Poker Player

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

QzNarsh的博客 621

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 an

不慌不忙、不急不躁 1832

UVA 131 - The Psychic Poker Player 暴力不解释

#include #include #include using namespace std; char t[][20] = {"straight-flush","four-of-a-kind","full-house","flush","straight" ,"three-of-a-kind","two-pairs","one-pair","highest-ca

泪无痕 741

uva131 The Psychic Poker Player

The Psychic Poker Player Time Limit: 3000MS     64bit IO Format: %lld & %llu Description In 5-card draw poker, a player is dealt a hand of five cards (which may be looked at)

keshuqi的博客 553
上一篇: kmp求字符串最小周期
下一篇: uva-110-Meta-Loopless Sorts
HuanTongH
博客等级 码龄12年 7粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值