题目链接: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. Knockout.Js官网学习(监控属性Observables)

    前言 1.创建一个ViewModel <script type="text/javascript"> //1.创建一个ViewModel var myViewModel ...

  2. Mysql导入导出 改密命令总结(笔记三)

    一.从数据库导出数据 注意这些语句的执行是在在没进入mysql命令行之前,在mysql命令行不行 C:\Windows\system32>导出命令 而不是 Mysql>导出命令 1.导出整 ...

  3. Laravel 5 基础(五)- 环境与配置

    .env 文件是配置文件,包括数据库配置信息,查看 config->database.php ,connections 里面包含了所有数据库的配置,可以在 default 中选择要使用的数据库. ...

  4. Mayan游戏 (codevs 1136)题解

    [问题描述] Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个7行5列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他方块之上.游戏通关是指在规定的 ...

  5. java作用域public ,private ,protected 及不写时的区别(转)

    在说明这四个关键字之前,我想就class之间的关系做一个简单的定 义,对于继承自己的class,base class可以认为他们都是自己的子 女,而对于和自己一个目录下的classes,认为都是自己的 ...

  6. Mongodb初学习--安装、试用

    MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. 在MongoDB中数据被分组存储在数据集中,被称为一个集合(Collection ...

  7. java reflect 初始学习 动态加载类

    首先要理解Class类: 在java 的反射中,Class.forName("com.lilin.Office") 使用类的全名,这样获取,不仅仅表示了类的类类型,同时还代表着类的 ...

  8. Swift学习初步(一)

    前几天刚刚将有关oc的教程草草的看了一遍,发现oc其实也不像传说的那么难.今天又开始马不停蹄的学习Swift因为我很好奇,到底苹果出的而且想要代替oc的编程语言应该是个什么样子呢?看了网上的一些中文教 ...

  9. 在JAVA中使用JSONObject生成json

    JSON是一种轻量级的数据交换格式,在现在的web开发中,是非常常见的.在没有方便的工具之前,我们或许会使用拼字符串的形式来生成json数组,今天我们使用一个json-lib.jar包来为我们实现生成 ...

  10. libevent 信号示例

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