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 ...
随机推荐
- struts2中valueStack,stackContext以及actionContext的关系
一,首先给出三者的定义 1.valueStack: 里面存放的是Action类中通过set方法设置的属性值(表单传过来的值等),由OGNL框架实现; 2.stackContext: 也是用来存值的,s ...
- Windows工作集内存
Windows任务管理器默认情况下,“内存(私人工作集)”列处于选中状态. 私人工作集是工作集的一个子集,它是描述每个进程所使用的内存数量的技术术语.私人工作集专门描述了某个进程正在使用的且无法与其他 ...
- jQuery Flickerplate 幻灯片
Flickerplate 是个轻量级 jQuery 插件,大小仅为 12 kb.它允许用户点击鼠标然后转换内容,非常容易使用,响应式,支持触摸设备 在线实例 默认 圆点导航位置 动画方式 深色主题 H ...
- ASP.NET检测到有潜在危险的 Request.Form 值解决方案汇总
ASP.NET检测到有潜在危险的 Request.Form 值解决方案汇总 当我们在网站中使用CKEditor等富文本编辑器时,大多都会遇到这样的到警告 这是因为ASP.NET默认开启对页面提交内容的 ...
- DevExpress GridControl使用方法总结
一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 (1).gridView.AddN ...
- andriod GridView
<?xml version="1.0" encoding="UTF-8"?> <GridView xmlns:android="ht ...
- R语言学习笔记:小试R环境
买了三本R语言的书,同时使用来学习R语言,粗略翻下来感觉第一本最好: <R语言编程艺术>The Art of R Programming <R语言初学者使用>A Beginne ...
- new与malloc的区别
看起来,它们的不同只是new比malloc用起来更方便而已.仅仅是这样吗?不是吗? 1 来源不同: 1)new/delete是C++中的操作符,而malloc/free是C中的标准库函数,需要库文件支 ...
- android多种布局的列表实现
最近有一个列表效果,需要一个列表有多种布局,最终效果如下: 这个我也问了同事以及开发群里的朋友,居然都没得到最优的实现方式的回答,看来这种复杂列表的需求还是比较少的,我自己也走了一些弯路,把我几个实现 ...
- nim2 取石头youxi
a先把石头分堆,然后bababa的顺序取石头,只能取其中一堆中的若干颗(不能不取) 这种问题先考虑 先取者的胜态问题 (1,1)先取者必败, 所以(1,x),当x>1时可以转换为(1,1)使后取 ...