题目链接: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. Gridview 行变色和行按钮调用前端js

    1.鼠标移动某一行 ,变色 protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Ro ...

  2. 选择两个字段时distinct位置的影响

    当选择两个字段时,例如:"select XX1, XX2 from tb; ",那么将distinct放在前一个字段XX1之前和放在后一个字段XX2之前,结果有什么不同呢? 先说结 ...

  3. memcache 简单入门应用

    1.memcache 简介和安装: 下载:下载文件,解压到某个地方. 2.数据存储格式 键值对,一个key对应一个值,一个值在内存中占用一个或多个4k大小的块. 3.php使用memcache的方式 ...

  4. Navicat Premium 11 For Mac 注册机

    http://mac.pcbeta.com/thread-138357-1-1.html

  5. php生成随机字符串和验证码的类

    网上有很多的php随机数与验证码的代码与文章,真正适用的没有几个. 索性自己搞一个吧. 开始本节的php教程 吧,以下代码的实现,主要做到可以很好区分一个get_code(),另一个create_ch ...

  6. Library工程No resource identifier found for attribute

    使用library工程中自定义属性无法识别问题 解决:xmlns:ptr="http://schemas.android.com/apk/res/包名, 改成xmlns:ptr=" ...

  7. [terry笔记]IMPDP报错ORA-39083 Object type TYPE failed to create ORA-02304

    今天在使用impdp导入的时候(同一数据库中转换schema),遇到了 ORA-39083: Object type TYPE failed to create with error: ORA-023 ...

  8. mysql外键设置(待测试)

    外键的定义语法:[CONSTRAINT symbol] FOREIGN KEY [id] (index_col_name, ...)    REFERENCES tbl_name (index_col ...

  9. poj 2631 Roads in the North

    题目连接 http://poj.org/problem?id=2631 Roads in the North Description Building and maintaining roads am ...

  10. JavaScript高级程序设计之动态脚本及动态样式

    1.动态加载脚本(src 原理,异步,支持跨域) var loadScript = function (url, callback) { var script = document.createEle ...