题目链接: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. 个人代码管理--svn

    通常开发中遇到自己电脑和公司电脑代码共享的问题.比如一些通用的库,图片等项目中基本通用. 一些项目库如google code, github内地访问又挺困难的,常常无法连接,或者慢死..还有就是必须开 ...

  2. ASP.NET MVC5学习笔记之Controller执行ControllerDescriptor和ActionDescriptor

    一. ControllerDescriptor说明 ControllerDescriptor是一个抽象类,它定义的接口代码如下: public abstract class ControllerDes ...

  3. STM32F0xx_SPI读写(Flash)配置详细过程

    Ⅰ.概述 关于SPI(Serial Peripheral Interface)串行外设接口可以说是单片机或者嵌入式软件开发人员必须掌握的一项通信方式,就是你在面试相关工作的时候都可能会问及这个问题.在 ...

  4. ROS多个master消息互通

    需求 有时候我们需要有几个不同的master, 他们之间要交换topic的内容,这时候就不能使用ros自带的设置同一个master的方法. 我们的处理方法是,构造一个client和一个server,他 ...

  5. Web Design:欧美人形剪影的404界面

    项目需求,必须得写个404界面,比较愁,因为网站属于那种电商+艺术品拍卖的网站,404界面不太好设计 很多时候网站直接代码报错输出404,不过设计过的404也有好处,比如改进用户体验.增强互动性之类的 ...

  6. 关于生成缩略图及水印图片时出现GDI+中发生一般性错误解决方法

    System.Drawing.Image OldImage = null; oldImage = System.Drawing.Image.FromFile(ImageUrl); 使用该方法读取图片时 ...

  7. [原创]PostgreSQL Plus Advanced Server监控工具PEM(一)

    一.概述 PEM是为数据库管理员.系统架构师和性能分析师为管理.监控和优化 PostgreSQL 和 EnterpriseDB 数据库服务器设计的图形化管理工具.旨在解决大量数据库服务器跨地域.精细化 ...

  8. IBM X3650 M4安装win 2008 Server操作指南

    由于IBM服务器是IBM原有的Linux系统,所以需要在此硬件上安装Win 2008 Server系统(以下简称win8),中间遇到了很多坑,在下面的描述中会阐述.以下是安装的整个步骤: 一.所需工具 ...

  9. 记录bigdesk中ElasticSearch的性能参数

    定时采集bigdesk中的Elasticsearch性能参数,并保存到数据库或ELK,以便于进行长期监控. 基于python脚本实现,脚本如下: #coding=gbk import httplibi ...

  10. 教你怎么安装Redis

    以下命令以root用户运行:#cd /tmp/#wget http://redis.googlecode.com/files/redis-2.6.11.tar.gz#tar xzf redis-2.6 ...