uva131 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). 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
| 6736778 | Accepted | 0 | 0 | 2923 |
2016-08-04 09:33:04
|
题目大意如下:这是一几局德州扑克游戏。给定5张初始手牌和5张牌的牌堆(可预知牌堆中的牌类、数字、花色以及顺序,即玩家具有超能力),可以拿手牌换牌堆最上方的牌,之后手牌丢弃,换到的牌不允许再换。
思路如下:先确定枚举和搜索的对象,本题的对象应该是要弃的手牌,由于考虑到换牌的数量和制定牌不定,我们要用到子集枚举的算法。而这里我们用增量法。
用string类配合cin(string是类,不能用scanf或printf,所以果断用cin和cout)之后,预处理牌的点数,将2~9和A、T、J、Q、K统一转化为数字。之后,用增量法枚举要换的牌,之后使用judge函数对它的花色和点数进行判断,这里要外加一个sort优化方便直接用if语句判断,记录最高分手牌则用一个常数数组记录同花顺~大牌的降序字符串数组,用数组的下标值来比较,记录最小值ans,最后按题目要求输出。
代码如下:(2KB)
#include<string>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
string cd[11];
string bthd[]={"straight-flush","four-of-a-kind","full-house","flush","straight","three-of-a-kind","two-pairs","one-pair","highest-card"};
int val[11],a[11],hd[6],ans;
int jud(int cur)
{
bool samecol=1;
for(int i=0;i<cur;i++){
hd[i]=val[a[i]];
if(cd[a[0]][1]!=cd[a[i]][1])samecol=0;
}
for(int i=cur;i<5;i++){
hd[i]=val[5+i-cur];
if(cd[a[0]][1]!=cd[5+i-cur][1])samecol=0;
}
sort(hd,hd+5);
bool flush=1;
for(int i=0;i<4;i++)
if((i||hd[0]!=1||hd[4]!=13)&&hd[i]+1!=hd[i+1])
{flush=0;break;}
if(samecol&&flush)return 0;
if((hd[0]==hd[1]||hd[3]==hd[4])&&hd[1]==hd[2]&&hd[2]==hd[3])return 1;
if((hd[0]==hd[1]&&hd[1]==hd[2]&&hd[3]==hd[4])||(hd[0]==hd[1]&&hd[2]==hd[3]&&hd[3]==hd[4]))return 2;
if(samecol)return 3;
if(flush)return 4;
if((hd[0]==hd[1]&&hd[1]==hd[2])||(hd[1]==hd[2]&&hd[2]==hd[3])||(hd[2]==hd[3]&&hd[3]==hd[4]))return 5;
if(((hd[0]==hd[1])&&(hd[2]==hd[3]||hd[3]==hd[4]))||(hd[1]==hd[2]&&hd[3]==hd[4]))return 6;
if(hd[0]==hd[1]||hd[1]==hd[2]||hd[2]==hd[3]||hd[3]==hd[4])return 7;
return 8;
}
void sub(int cur)
{
ans=min(ans,jud(cur));
int s=cur?a[cur-1]+1:0;
for(int i=s;i<5;i++){
a[cur]=i;
sub(cur+1);
}
}
void solve()
{
for(int i=0;i<10;i++){
if(cd[i][0]=='T')val[i]=10;
else if(cd[i][0]=='J')val[i]=11;
else if(cd[i][0]=='Q')val[i]=12;
else if(cd[i][0]=='K')val[i]=13;
else if(cd[i][0]=='A')val[i]=1;
else val[i]=cd[i][0]-'0';
}
ans=8;
sub(0);
}
void out()
{
cout<<"Hand: ";
for(int i=0;i<5;i++)
cout<<cd[i]<<" ";
cout<<"Deck: ";
for(int i=5;i<10;i++)
cout<<cd[i]<<" ";
cout<<"Best hand: "<<bthd[ans]<<endl;
}
int main()
{
while(cin>>cd[0]){
for(int i=1;i<10;i++)
cin>>cd[i];
solve();
out();
}
return 0;
}
uva131 The Psychic Poker Player的更多相关文章
- UVa 131 - The Psychic Poker Player
题目:手里有五张牌,桌上有一堆牌(五张).你能够弃掉手中的k张牌,然后从牌堆中取最上面的k个. 比較规则例如以下:(按优先级排序) 1.straight-flush:同花顺.牌面为T(10) - A, ...
- 备战NOIP每周写题记录(一)···不间断更新
※Recorded By ksq2013 //其实这段时间写的题远远大于这篇博文中的内容,只不过那些数以百记的基础题目实在没必要写在blog上; ※week one 2016.7.18 Monday ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- iOS Storyboard全解析
来源:http://iaiai.iteye.com/blog/1493956 Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果, ...
- iOS Storyboard 的基本用法
(Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果,我贴上本教程所完成的Storyboard的截图: 现 在,你就可以清楚的看 ...
- Java-->发牌流程修改版
--> 这一次要封装得狠一点... package com.xm.ddz; // 每一张牌的属性 public class Card { private String flowerColor; ...
- [IOS] Storyboard全解析-第一部分
(Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果,我贴上本教程所完成的Storyboard的截图: 现在,你就可以清楚的看到这 ...
- 最新iOS 6 in Xcode4.5新特性——Storyboard和属性自动绑定
最新iOS 6 in Xcode4.5新特性编程之二(上)——Storyboard和属性自动绑定 从Xcode 4.3开始,Storyboard 就是iOS 5和iOS 6中令人兴奋的一个新特性,他将 ...
- java练习:质数,匿名内部类创建接口,抽象类派生子类,画圆,字节截取字符串,数字变钱币,五子棋,梭哈
java学习-质数的孤独 正在看质数的孤独,,,于是写了一个练习代码,输出1-100之间的质数 代码比较烂.待完善吧. 这里用到了continue和break,continue指结束当前轮次循环,跳入 ...
随机推荐
- SharePoint 开启网站匿名访问图文详解
SharePoint 开启网站匿名,需要先开启web application的匿名访问,然后开启site的匿名访问.特别的,site可以选择整个网站开启或者列表和库开启匿名,如果选择列表和库开启匿名, ...
- SharePoint Online 创建门户网站系列之准备篇
前 言 门户是SharePoint自推出以来,就非常适合的一种站点类型,在Server版本中,发布站点的应用非常广泛.这里,我们以一个个简单的例子,然后以一个固定的项目Demo,为大家演示如何一步步在 ...
- 好推二维码如何通过应用宝微下载支持微信自动打开APP下载?
好推二维码 官网 http://www.hotapp.cn 1. 为什么使用应用宝微下载? APP下载二维码,通过微信扫描下载的时候,微信目前只支持应用宝微下载,才能在微信里直接打开下载,否则就需要在 ...
- struts理解
最近大家都在找工作,我好迷茫,觉得自己会的东西太少了.所以决定开始学习SSH三大框架. 首先是struts. struts是基于mvc模式的框架.(struts其实也是servlet封装,提高开发效率 ...
- android加固系列—5.加固前先学会破解,hook(钩子)jni层系统api
[版权所有,转载请注明出处.出处:http://www.cnblogs.com/joey-hua/p/5138585.html] crackme项目jni的关键代码(项目地址见文章底部),获取当前程序 ...
- The Genymotion Virtual device could not obtain an IP address解决办法
打开Genymotion运行虚拟机提示如下错误: The Genymotion Virtual device could not obtain an IP address.For an unknown ...
- App开发流程之右滑返回手势功能
iOS7以后,导航控制器,自带了从屏幕左边缘右滑返回的手势功能. 但是,如果自定义了导航栏返回按钮,这项功能就失效了,需要自行实现.又如果需要修改手势触发范围,还是需要自行实现. 广泛应用的一种实现方 ...
- php示例代码之使用mysql_fetch_object函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- servlet 学习(一)
一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...
- Javascript之旅——第九站:吐槽function
说到funciton,也是我对js非常吐槽的一点,封装的让我眼瞎,马蛋的,哥只能大眼睁着去黑盒的使用,简直只有完完全全的听各类图书对 function的道听图说,完全没有做到一点点的眼见为实. 一:f ...
