题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1111

A poker hand consists of 5 cards dealt from the deck. Poker hands are ranked by the following partial order from lowest to highest

  • High Card. Hands which do not fit any higher category are ranked by the value of their highest card. If the highest cards have the same value, the hands are ranked by the next highest, and so on.
  • Pair. 2 of the 5 cards in the hand have the same value. Hands which both contain a pair are ranked by the value of the cards forming the pair. If these values are the same, the hands are ranked by the values of the cards not forming the pair, in decreasing order.
  • Two Pairs. The hand contains 2 different pairs. Hands which both contain 2 pairs are ranked by the value of their highest pair. Hands with the same highest pair are ranked by the value of their other pair. If these values are the same the hands are ranked by the value of the remaining card.
  • Three of a Kind. Three of the cards in the hand have the same value. Hands which both contain three of a kind are ranked by the value of the 3 cards.
  • Straight. Hand contains 5 cards with consecutive values. Hands which both contain a straight are ranked by their highest card.
  • Flush. Hand contains 5 cards of the same suit. Hands which are both flushes are ranked using the rules for High Card.
  • Full House. 3 cards of the same value, with the remaining 2 cards forming a pair. Ranked by the value of the 3 cards.
  • Four of a kind. 4 cards with the same value. Ranked by the value of the 4 cards.
  • Straight flush. 5 cards of the same suit with consecutive values. Ranked by the highest card in the hand.

Your job is to compare several pairs of poker hands and to indicate which, if either, has a higher rank.

题意:两手扑克牌,一手各5张牌,按照接下来的规则比大小。下面的规则是按照一手牌从大到小介绍的。

  规则一:5张牌花色一样,大小连着的,俗称“同花顺”。同花顺的大小根据最大值的判断。

  规则二:有4张牌一样大的。就是说5张牌中能组成炸弹。这样的牌通过那4张牌的大小再来进行比较大小。比如(A,3,3,3,3)和(9,4,4,4,4)就是后者大。

  规则三:3张牌一样大,另外两张牌组成一对。满足规则三的两手牌根据那3张牌再进行大小比较。

  规则四:5张牌同色,大小比较就看牌的大小了。

  规则五:5张牌大小连着组成了顺子,大小看最大值。

  规则六:3张牌相同,大小看3张牌的值的大小。

  规则七:组成两对和一张单牌,大小看那两对的大小,如果还相同的就看那单牌。

  规则八:组成一队,大小先看这一对,然后再比较剩下的三张散牌。

  规则九:5张牌没什么组合的,散牌,就单纯的比较大小。

解法:按照这几个规则模拟即可。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
struct node
{
int value;
char color;
friend bool operator <(node a,node b)
{
return a.value > b.value;
}
}an[],bn[];
int cmp(int i,int j) {return i<j; }
int getvalue(char *str)
{
if (str[]>=''&&str[]<='') return str[]-'';
if (str[]=='T') return ;
if (str[]=='J') return ;
if (str[]=='Q') return ;
if (str[]=='K') return ;
if (str[]=='A') return ;
}
int color_ok(node *cn,int k)
{
int flag=;
for (int i= ;i<= ;i++) if (cn[i].color!=cn[].color) flag=;
for (int i= ;i<= ;i++) if (cn[i].value!=cn[i+].value+) flag=;
if (cn[].value!=k) flag=;
if (flag) return ;
return ;
}
int four_ok(node *cn,int k)
{
int cnt=;
for (int i= ;i<= ;i++) if (cn[i].value==k) cnt++;
if (cnt==) return ;
return ;
}
int full_ok(node *cn,int k)
{
int cnt=;
int u=,v=;
for (int i= ;i<= ;i++)
{
if (cn[i].value==k) cnt++;
else if (!u) u=i;
else v=i;
}
if (cnt==)
{
if (cn[u].value==cn[v].value) return ;
else return ;
}
else return ;
}
int same_color(node *cn)
{
for (int i= ;i<= ;i++) if (cn[i].color!=cn[].color) return ;
return ;
}
int straight_ok(node *cn,int k)
{
int flag=;
for (int i= ;i<= ;i++) if (cn[i].value!=cn[i+].value+) flag=;
if (cn[].value!=k) flag=;
if (flag) return ;
return ;
}
int three_ok(node *cn,int k)
{
int cnt=;
for (int i= ;i<= ;i++) if (cn[i].value==k) cnt++;
if (cnt==) return ;
return ;
}
int first_ok(node *cn,int k)
{
int cnt=;
for (int i= ;i<= ;i++) if (cn[i].value==k) cnt++;
if (cnt==) return ;
return ;
}
int main()
{
char str[];
while (scanf("%s",str)!=EOF)
{
an[].value=getvalue(str);an[].color=str[];
for (int i= ;i<= ;i++)
{
scanf("%s",str);
an[i].value=getvalue(str);
an[i].color=str[];
}
for (int i= ;i<= ;i++)
{
scanf("%s",str);
bn[i].value=getvalue(str);
bn[i].color=str[];
}
sort(an+,an++);sort(bn+,bn++);
int OK=;
int flag1=,flag2=;
///Straight flush
for (int i= ;i>= ;i--)
{
flag1=flag2=;
if (color_ok(an,i)) flag1=;
if (color_ok(bn,i)) flag2=;
if (flag1 && flag2) {printf("Tie.\n");OK=;break; }
if (flag1) {printf("Black wins.\n");OK=;break; }
if (flag2) {printf("White wins.\n");OK=;break; }
}
if (OK) continue;
///Four of a kind
for (int i= ;i>= ;i--)
{
flag1=flag2=;
if (four_ok(an,i)) flag1=;
if (four_ok(bn,i)) flag2=;
if (flag1 && flag2) {printf("Tie.\n");OK=;break; }
if (flag1) {printf("Black wins.\n");OK=;break; }
if (flag2) {printf("White wins.\n");OK=;break; }
}
if (OK) continue;
///Full House
for (int i= ;i>= ;i--)
{
flag1=flag2=;
if (full_ok(an,i)) flag1=;
if (full_ok(bn,i)) flag2=;
if (flag1 && flag2) {printf("Tie.\n");OK=;break; }
if (flag1) {printf("Black wins.\n");OK=;break; }
if (flag2) {printf("White wins.\n");OK=;break; }
}
if (OK) continue;
///Flush
flag1=flag2=;
if (same_color(an)) flag1=;
if (same_color(bn)) flag2=;
if (flag1 && flag2)
{
int ok=;
for (int i= ;i<= ;i++)
{
if (an[i].value>bn[i].value) {printf("Black wins.\n");ok=;OK=;break; }
else if (an[i].value<bn[i].value) {printf("White wins.\n");ok=;OK=;break; }
}
if (!ok) {printf("Tie.\n");OK=;continue;}
}
if (flag1&&!OK) {printf("Black wins.\n");OK=;continue; }
if (flag2&&!OK) {printf("White wins.\n");OK=;continue; }
if (OK) continue;
///Straight
for (int i= ;i>= ;i--)
{
flag1=flag2=;
if (straight_ok(an,i)) flag1=;
if (straight_ok(bn,i)) flag2=;
if (flag1 && flag2) {printf("Tie.\n");OK=;break; }
if (flag1) {printf("Black wins.\n");OK=;break; }
if (flag2) {printf("White wins.\n");OK=;break; }
}
if (OK) continue;
///Three of a Kind
for (int i= ;i>= ;i--)
{
flag1=flag2=;
if (three_ok(an,i)) flag1=;
if (three_ok(bn,i)) flag2=;
if (flag1 && flag2) {printf("Tie.\n");OK=;break; }
if (flag1) {printf("Black wins.\n");OK=;break; }
if (flag2) {printf("White wins.\n");OK=;break; }
}
if (OK) continue;
///Two Pairs
for (int i= ;i>= ;i--)
{
flag1=flag2=;
int k1=,k2=;
if (first_ok(an,i))
{
for (int j=i- ;j>= ;j--)
{
if (first_ok(an,j)) {flag1=;k1=j;break;}
}
}
if (first_ok(bn,i))
{
for (int j=i- ;j>= ;j--)
{
if (first_ok(bn,j)) {flag2=;k2=j;break;}
}
}
if (flag1 && flag2 && k1==k2)
{
int u=,v=;
for (int j= ;j<= ;j++) if (an[j].value!=i && an[j].value!=k1) {u=j;break; }
for (int j= ;j<= ;j++) if (bn[j].value!=i && bn[j].value!=k2) {v=j;break; }
if (an[u].value==bn[v].value) {printf("Tie.\n");OK=;break; }
else if (an[u].value>bn[v].value) {printf("Black wins.\n");OK=;break; }
else {printf("White wins.\n");OK=;break; }
}
if (flag1 && flag2 && !OK && k1!=k2)
{
if (k1>k2) {printf("Black wins.\n");OK=;break; }
else {printf("White wins.\n");OK=;break; }
}
if (flag1) {printf("Black wins.\n");OK=;break; }
if (flag2) {printf("White wins.\n");OK=;break; }
}
if (OK) continue;
///Pair
for (int i= ;i>= ;i--)
{
flag1=flag2=;
if (first_ok(an,i)) flag1=;
if (first_ok(bn,i)) flag2=;
if (flag1 && flag2)
{
int a[],b[];
int c=,d=;
for (int j= ;j<= ;j++) if (an[j].value!=i) a[c++]=an[j].value;
for (int j= ;j<= ;j++) if (bn[j].value!=i) b[d++]=bn[j].value;
sort(a,a+c,cmp);sort(b,b+d,cmp);
int flag=;
for (int j= ;j< ;j++)
{
if (a[j]>b[j]) {printf("Black wins.\n");flag=;OK=;break; }
else if (a[j]<b[j]) {printf("White wins.\n");flag=;OK=;break; }
}
if (flag==) {printf("Tie.\n");OK=;break; }
}
if (flag1&&!OK) {printf("Black wins.\n");OK=;break; }
if (flag2&&!OK) {printf("White wins.\n");OK=;break; }
}
if (OK) continue;
///High Card
int flag=;
for (int i= ;i<= ;i++)
{
if (an[i].value>bn[i].value) {printf("Black wins.\n");flag=;OK=;break; }
else if (an[i].value<bn[i].value) {printf("White wins.\n");flag=;OK=;break; }
}
if (!flag) {printf("Tie.\n");continue; }
}
return ;
}

ZOJ 1111 Poker Hands的更多相关文章

  1. ZOJ 1111 Poker Hands --复杂模拟

    昨天晚上写的,写了一个多小时,9000+B,居然1A了,爽. 题意:玩扑克,比大小.规则如下: 题意很简单,看过赌神的人都知道,每人手中5张排,比牌面大小,牌面由大到小分别是(这里花色无大小),级别从 ...

  2. [ZOJ 3839] Poker Face (递归)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3839 题目大意:画脸..每张脸是上一个脸倒过来加上眼睛.. 注意 ...

  3. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  4. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  5. 137 - ZOJ Monthly, November 2014 - J Poker Face

    Poker Face Time Limit: 2 Seconds      Memory Limit: 65536 KB As is known to all, coders are lack of ...

  6. ZOJ 3494 BCD Code(AC自动机+数位DP)

    BCD Code Time Limit: 5 Seconds      Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...

  7. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  8. zoj 3829 Known Notation

    作者:jostree 转载请说明出处 http://www.cnblogs.com/jostree/p/4020792.html 题目链接: zoj 3829 Known Notation 使用贪心+ ...

  9. HDU 4430 &amp; ZOJ 3665 Yukari&#39;s Birthday(二分法+枚举)

    主题链接: HDU:pid=4430" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=4430 ...

随机推荐

  1. winfrom之动态控件生成以及保存动态空间的数据

    前些天要完成一个winform程序,里面涉及到动态控件的添加以及保存动态空间中数据的保存,效果如下 初始化时: 点击添加阶梯价后:(点击一下,动态添加一行) 那么接下来,我们就具体的讲下代码实现: 首 ...

  2. SQL服务器更改名称后

    SQL服务器更改名称后 编写人:CC阿爸 2014-6-15 在日常SQL 2005数据库的操作中,有时安装完成数据库后,再更名,造成部分SQL服务不能正常使用(在SQL2000 时,想都别想更名了) ...

  3. Silverlight 独立存储(IsolatedStorageFile)

    1.在Web中添加天气服务引用地址 http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl 2.在Web中添加Wcf服务接口I ...

  4. compareTo & toString

    public class UnAssignedRecord implements Comparable<UnAssignedRecord> { private String time; / ...

  5. encodeURIComponent编码后java后台的解码

    解决方法一: JavaScript: window.self.location="searchbytext.action?searchtext="+encodeURICompone ...

  6. C# winform combobox控件中子项加删除按钮(原创)

    效果如下图,本人网上搜索资料加上自己的研究终于实现了在combobox子项中加上删除按钮. 一.窗体中的代码: using System; using System.Collections.Gener ...

  7. group by和distinct语句的执行顺序

    同一条语句之中,如果同时有group by和distinct语句,是先group by后distinct,还是先distinct后group by呢? 先说结论:先group by后distinct. ...

  8. Yii中使用PHPexcel获取excel中数据

    1.view中代码如下: <form name="frmBatchSettle" id="" action="" method=&qu ...

  9. WIN8+VS2013编写发布WCF之三(调用)

    在文二中部署成功后就可以在客户端程序中使用服务了...使用服务的过程总是这么酣畅淋漓.当然,对应文二中的三种部署方式,我也会在此描述三种使用方式,一一对应. 都是新建个程序了,然后开始介绍. 一.VS ...

  10. 第八节 C#的using语句

    前面的代示例展示了如果调用一个类型的Dispose或Close方法.如果决定显式的调用这两个方法之一,强烈建议吧他们放在一个异常处理finally块中.这样可以保证清理代码得到执行,因此,前代码示例可 ...