ZOJ 1111 Poker Hands --复杂模拟
昨天晚上写的,写了一个多小时,9000+B,居然1A了,爽。
题意:玩扑克,比大小。规则如下:
题意很简单,看过赌神的人都知道,每人手中5张排,比牌面大小,牌面由大到小分别是(这里花色无大小),级别从高到低依次为:
1.同花顺:牌面一样,只比较最大的看谁大,一样大则平手
2.四条:四个一样的,看这四个一样的中谁大谁赢
3.葫芦:三条+一对,看三条中谁的牌面大
4.同花:都是同花就按从大到小比较,看谁的更大
5.顺子:都是顺子看最大的谁大,一样则平手
6.三条:三条看三条中谁的牌面大
7.两对: 两对就看谁的对子大,都一样大比单牌
8.一对: 比对子,一样则比单牌
9.单排:按顺序比较大小,大者胜
知道规则了就搞就行了。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 100007 struct node
{
int num,suit;
}a[],b[];
int BigstPair[],SecondPair[],Remain[]; //
int k[][]; //
int m[][]; // int cmp(node ka,node kb)
{
return ka.num < kb.num;
} pair<int,int> solve(node a[],int tag)
{
int i,j;
sort(a,a+,cmp);
int level = ;
int val = ;
int flag = ;
for(i=;i<;i++)
{
if(a[i].suit != a[i-].suit)
break;
}
if(i == )
{
for(j=;j<;j++)
{
if(a[j].num != a[j-].num+)
break;
}
if(j == )
return make_pair(level,a[].num);
}
//
level--;
if((a[].num == a[].num && a[].num == a[].num && a[].num == a[].num)||(a[].num == a[].num && a[].num == a[].num && a[].num == a[].num))
{
if(a[].num == a[].num)
return make_pair(level,a[].num);
else if(a[].num == a[].num)
return make_pair(level,a[].num);
}
//
level--;
if(a[].num == a[].num && a[].num == a[].num && a[].num == a[].num)
return make_pair(level,a[].num);
if(a[].num == a[].num && a[].num == a[].num && a[].num == a[].num)
return make_pair(level,a[].num);
//
level--;
if(a[].suit == a[].suit && a[].suit == a[].suit && a[].suit == a[].suit && a[].suit == a[].suit)
{
k[][tag] = a[].num;
k[][tag] = a[].num;
k[][tag] = a[].num;
k[][tag] = a[].num;
k[][tag] = a[].num;
return make_pair(level,a[].num);
}
//
level--;
for(i=;i<;i++)
{
if(a[i].num != a[i-].num+)
break;
}
if(i == )
return make_pair(level,a[].num);
//
level--;
int cnt = ;
for(i=;i>=;i--)
{
if(a[i].num == a[i+].num)
{
cnt++;
if(cnt >= )
return make_pair(level,a[i].num);
}
else
cnt = ;
}
//
level--;
if(a[].num == a[].num && a[].num == a[].num)
{
BigstPair[tag] = a[].num;
SecondPair[tag] = a[].num;
Remain[tag] = a[].num;
return make_pair(level,BigstPair[tag]);
}
if(a[].num == a[].num && a[].num == a[].num)
{
BigstPair[tag] = a[].num;
SecondPair[tag] = a[].num;
Remain[tag] = a[].num;
return make_pair(level,BigstPair[tag]);
}
if(a[].num == a[].num && a[].num == a[].num)
{
BigstPair[tag] = a[].num;
SecondPair[tag] = a[].num;
Remain[tag] = a[].num;
return make_pair(level,BigstPair[tag]);
}
//
level--;
if(a[].num == a[].num)
{
m[][tag] = a[].num;
m[][tag] = a[].num;
m[][tag] = a[].num;
m[][tag] = a[].num;
return make_pair(level,m[][tag]);
}
if(a[].num == a[].num)
{
m[][tag] = a[].num;
m[][tag] = a[].num;
m[][tag] = a[].num;
m[][tag] = a[].num;
return make_pair(level,m[][tag]);
}
if(a[].num == a[].num)
{
m[][tag] = a[].num;
m[][tag] = a[].num;
m[][tag] = a[].num;
m[][tag] = a[].num;
return make_pair(level,m[][tag]);
}
if(a[].num == a[].num)
{
m[][tag] = a[].num;
m[][tag] = a[].num;
m[][tag] = a[].num;
m[][tag] = a[].num;
return make_pair(level,m[][tag]);
}
//9 High Cards
level--;
k[][tag] = a[].num;
k[][tag] = a[].num;
k[][tag] = a[].num;
k[][tag] = a[].num;
k[][tag] = a[].num;
return make_pair(level,k[][tag]);
} int compare(pair<int,int> ka,pair<int,int> kb)
{
if(ka.first == kb.first)
{
if(ka.first == || ka.first == ) //flush or high card
{
if(k[][] == k[][])
{
if(k[][] == k[][])
{
if(k[][] == k[][])
{
if(k[][] == k[][])
{
if(k[][] == k[][])
return ;
else if(k[][] > k[][])
return ;
else
return -;
}
else if(k[][] > k[][])
return ;
else
return -;
}
else if(k[][] > k[][])
return ;
else
return -;
}
else if(k[][] > k[][])
return ;
else
return -;
}
else if(k[][] > k[][])
return ;
else
return -;
}
else if(ka.first == ) //two pair
{
if(BigstPair[] == BigstPair[])
{
if(SecondPair[] == SecondPair[])
{
if(Remain[] == Remain[])
return ;
else if(Remain[] > Remain[])
return ;
else
return -;
}
else if(SecondPair[] > SecondPair[])
return ;
else
return -;
}
else if(BigstPair[] > BigstPair[])
return ;
else
return -;
}
else if(ka.first == ) //pair
{
if(m[][] == m[][])
{
if(m[][] == m[][])
{
if(m[][] == m[][])
{
if(m[][] == m[][])
return ;
else if(m[][] > m[][])
return ;
else
return -;
}
else if(m[][] > m[][])
return ;
else
return -;
}
else if(m[][] > m[][])
return ;
else
return -;
}
else if(m[][] > m[][])
return ;
else
return -;
}
else
{
if(ka.second == kb.second)
return ;
else if(ka.second > kb.second)
return ;
else
return ;
}
}
else
{
if(ka.first > kb.first)
return ;
else if(ka.first < kb.first)
return -;
}
} int main()
{
int i,j;
char ss[][];
while(scanf("%s",ss[])!=EOF)
{
for(i=;i<;i++)
scanf("%s",ss[i]);
for(i=;i<;i++)
{
char pre = ss[i][];
char back = ss[i][];
if(pre >= '' && pre <= '')
a[i].num = pre-'';
else if(pre == 'T')
a[i].num = ;
else if(pre == 'J')
a[i].num = ;
else if(pre == 'Q')
a[i].num = ;
else if(pre == 'K')
a[i].num = ;
else if(pre == 'A')
a[i].num = ;
// 0:C 1:D 2:H 3:S
if(back == 'C')
a[i].suit = ;
else if(back == 'D')
a[i].suit = ;
else if(back == 'H')
a[i].suit = ;
else
a[i].suit = ;
}
for(i=;i<;i++)
{
char pre = ss[i][];
char back = ss[i][];
if(pre >= '' && pre <= '')
b[i-].num = pre-'';
else if(pre == 'T')
b[i-].num = ;
else if(pre == 'J')
b[i-].num = ;
else if(pre == 'Q')
b[i-].num = ;
else if(pre == 'K')
b[i-].num = ;
else if(pre == 'A')
b[i-].num = ;
// 0:C 1:D 2:H 3:S
if(back == 'C')
b[i-].suit = ;
else if(back == 'D')
b[i-].suit = ;
else if(back == 'H')
b[i-].suit = ;
else
b[i-].suit = ;
}
int res = compare(solve(a,),solve(b,));
if(res > )
puts("Black wins.");
else if(res == )
puts("Tie.");
else
puts("White wins.");
}
return ;
}
ZOJ 1111 Poker Hands --复杂模拟的更多相关文章
- ZOJ 1111 Poker Hands
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1111 A poker hand consists of 5 ca ...
- UVALive 3486/zoj 2615 Cells(栈模拟dfs)
这道题在LA是挂掉了,不过还好,zoj上也有这道题. 题意:好大一颗树,询问父子关系..考虑最坏的情况,30w层,2000w个点,询问100w次,貌似连dfs一遍都会TLE. 安心啦,这肯定是一道正常 ...
- ZOJ 3326 An Awful Problem 模拟
只有在 Month 和 Day 都为素数的时候才能得到糖 那就模拟一遍时间即可. //#pragma comment(linker, "/STACK:16777216") //fo ...
- ZOJ 2476 Total Amount 字符串模拟
- Total Amount Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit ...
- zoj 3314 CAPTCHA(纯模拟)
题目 有些人用深搜写的,当然我这弱弱的,只理解纯模拟... 纯模拟,第一次写了那么长的代码,我自己也是够坚韧不拔的,,,,必须留念啊!!! 注意,G包含C,E包含L,R包含P,(照图说O应该不包含C, ...
- ZOJ 2477 Magic Cube 暴力,模拟 难度:0
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1477 用IDA*可能更好,但是既然时间宽裕数据简单,而且记录状态很麻烦,就直接 ...
- [ZOJ 3839] Poker Face (递归)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3839 题目大意:画脸..每张脸是上一个脸倒过来加上眼睛.. 注意 ...
- [ZOJ 1006] Do the Untwist (模拟实现解密)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6 题目大意:给你加密方式,请你求出解密. 直接逆运算搞,用到同余定理 ...
- ZOJ 1057 Undercut(简单模拟)
Undercut 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=57 题目大意:a card game,two pla ...
随机推荐
- xmapp的安装
搭建网站常识性的你首先得搭建一个服务器. 首先APACHE是世界使用排名第一的WEB服务器软件,但是安装APACHE WEB服务器并不容易.如果你想添加MYSQL.PHP和PERL,那就更难了.所以可 ...
- [Tool] Windows 8.1安装SQL Server
[Tool] Windows 8.1安装SQL Server 问题情景 因为工作的关系,需要在Windows 8.1.64Bit设备上安装SQL Server 2012.本来以为是个只要按下一步就可以 ...
- ABAP常用函数集锦
函数名 描述 SD_VBAP_READ_WITH_VBELN 根据销售订单读取表vbap中的信息EDIT_LINES 把READ_TEXT返回的LINES中的行按照TDFORMAT=“*”重新组织VI ...
- Microsoft Dynamics CRM 2013 安装程序及SDK 下载地址
Microsoft Dynamics CRM 2013 已经具有相关资料 2013 Setup (Microsoft Dynamics CRM Server 2013) 下载地址: http://ww ...
- 2015年第14本(英文第10本):The A.B.C. Murders (A.B.C谋杀案)
书名:The ABC Murders 推荐指数:5星 作者:Agatha Christie 单词数:7万 不重复单词数:不详 首万词不重复单词数:不详 蓝思值:740 阅读时间:2015年7月18日 ...
- MacBook Air 使用技巧
1.Finder 相当于资源管理器 Launchpad 相当于桌面 Safari 浏览器 2.快捷键 * cmd+shift+3: 捕获整 ...
- JSP内置对象--request对象
本文主要介绍JSP中的request对象 request对象的主要方法: setAttribute(String name,Object):设置名字为name的request的参数值 getAttri ...
- iOS 工厂方法模式
iOS工厂方法模式 什么是工厂方法模式? 工厂方法模式和简单工厂模式十分类似,大致结构是基本类似的.不同在于工厂方法模式对工厂类进行了进一步的抽象,将之前的一个工厂类抽象成了抽象工厂和工厂子类,抽象工 ...
- INFORMATICA 的调优之 INFORMATICA SERVER TUNING
INFORMATICA SERVER的调优我认为主要从两个级别来做,一个是MAPPING级别,一个是SESSION级别. 对于MAPPING级别的调优: 一 对MAPPING数据流向的优化: 1 控 ...
- Oracle instr函数与SqlServer charindex的区别
INSTR(C1,C2[,I[,J]]) [功能]在一个字符串中搜索指定的字符,返回发现指定的字符的位置; [说明]多字节符(汉字.全角符等),按1个字符计算 [参数] C1 被搜索的字符串 ...