ZOJ 1111 Poker Hands
题目链接: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的更多相关文章
- ZOJ 1111 Poker Hands --复杂模拟
昨天晚上写的,写了一个多小时,9000+B,居然1A了,爽. 题意:玩扑克,比大小.规则如下: 题意很简单,看过赌神的人都知道,每人手中5张排,比牌面大小,牌面由大到小分别是(这里花色无大小),级别从 ...
- [ZOJ 3839] Poker Face (递归)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3839 题目大意:画脸..每张脸是上一个脸倒过来加上眼睛.. 注意 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- 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 ...
- ZOJ 3494 BCD Code(AC自动机+数位DP)
BCD Code Time Limit: 5 Seconds Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
- zoj 3829 Known Notation
作者:jostree 转载请说明出处 http://www.cnblogs.com/jostree/p/4020792.html 题目链接: zoj 3829 Known Notation 使用贪心+ ...
- HDU 4430 & ZOJ 3665 Yukari's Birthday(二分法+枚举)
主题链接: HDU:pid=4430" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=4430 ...
随机推荐
- sql批量修改插入数据
1.批量修改 select 'update 读者库 set 单位代码='''+新单位代码+''' where 单位代码='''+单位代码+'''' from 读者单位 ,)<'L' and is ...
- C#虚方法认识
C# 中虚方法 1.具体的是new后面具体是那个类,调用的是该类的实现方法.不和基类有关,虽然可以将子类赋值给基类句柄. 但是具体还是调用具体实例化的方法.
- U盘启动
2014.4.3修改 其实用U盘制作系统也可以下载一个软碟通UltraISO,就可以很方便的制作. ----以前的版本 用U盘装系统,很方便快捷,下面这个网站介绍的比较详细,于是自己整理了一下,作为收 ...
- DELPHI XE5 FOR ANDROID 模仿驾考宝典 TMEMO 控件随着字数增多自动增高
在一个安卓需求中,需要模仿驾考宝典的详解部分.琢磨了好几天.终于搞定: MemoAns.Height:=10;//MEMO控件赋初始高度值 MemoAns.Lines.Clear; MemoAns.W ...
- C# 验证IP是否正确简易方法 源代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 在ASP.NET MVC中以post方式传递数组参数的示例
最近在工作中用到了在ASP.NET MVC中以post方式传递数组参数的情况,记录下来,以供参考. 一.准备参数对象 在本例中,我会传递两个数组参数:一个字符串数组,一个自定义对象数组.这个自定义对象 ...
- 问题记录-Activity跳转后显示空白界面
前两天写一个简易安卓记事本,从主界面跳转到添加内容界面总是显示空白. 明明有setContentView xml文件在可视化开发环境下也正常显示.后经前辈指点,原来是复写onCreate函数时出现了问 ...
- 第七节:使用实现了dispose模式的类型
知道类型如何实现dispose模式之后,接下来看一下开发人员怎样使用提供了dispose模式的类型.这里不再讨论前面的SafeHandle类,而是讨论更常用的FileStream类. 可以利用File ...
- LinearRegressionWithRegularization
在线性回归的基础上加上正则项: # -*-coding:utf-8 -*- ''' Created on 2016年12月15日 @author: lpworkdstudy ''' import nu ...
- wpf 动画 2个窗体切换
<Window x:Class="翻转.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xam ...