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 ...
随机推荐
- .NET Core Runtime IDentifier (RID) catalog
转载至:https://docs.microsoft.com/zh-cn/dotnet/articles/core/rid-catalog What are RIDs? RID is short fo ...
- 硅谷新闻4--解决页签手指按下从左到右滑动的bug
有一种方法可以阻止父层的View截获touch事件,就是调用 getParent().requestDisallowInterceptTouchEvent(true);方法.一旦底层View收到tou ...
- mysql metadata lock锁
很多情况下,很多问题从理论上或者管理上而言都是可以避免或者说很好解决的,但是一旦涉及到现实由于管理或者协调或者规范执行的不够到位,就会出现各种各样本不该出现的问题,这些问题的通常在生产环境并不会出现, ...
- HTML5中的音视频处理
* 音视频处理 * 视频处理 * 基本内容 * 使用Flash技术处理HTML页面中的视频内容 * 包含音频.动画.网页游戏等 * 特点 * 浏览器原生不支持(IE浏览器要求安装ActiveX组件) ...
- ASP.NET获取请求的url信息汇总
ASP.NET获取请求的url信息汇总 最近做项目需要处理一个用代码获取当前网站的域名或ip信息的问题,于是尝试了ASP.NET中各种获取url信息的方法,在此总结一下: 在Global.asax文件 ...
- Win10安装framework3.5
.NET少不了framewrok,其版本也比较多,默认情况下win7及上版本没有安装framework3.5,但有些软件又需要它,比如arcgis软件在安装时会检测是否存在3.5,如果没有,将不会正常 ...
- Android 五大布局
Android 五大布局: FrameLayout(框架布局),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),Table ...
- 【读书笔记】iOS-GCD-block-后台运行
当一个app按home键退出的时候,只有最多5秒的时间做一些保存或清理资源的工作.但是调用beginBackgroundTaskWithExpirationHandler方法,可以最多有10分时间在后 ...
- IOS 网络浅析-(三 NSURLConnection代理)
对于现在的iOS开发,用法简单,最古老最经典最直接的NSURLConnection的作用不是很大,但是作为一名ios开发者,我们应该拥有一颗热爱学习的心,下面通过代码的实现简单介绍一下NSURLCon ...
- C++中派生类对象的内存布局
主要从三个方面来讲: 1 单一继承 2 多重继承 3 虚拟继承 1 单一继承 (1)派生类完全拥有基类的内存布局,并保证其完整性. 派生类可以看作是完整的基类的Object再加上派生类自己的Objec ...