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 ...
随机推荐
- Java与线程
导语 我们知道,new一个thread,调用它的start的方法,就可以创建一个线程,并且启动该线程,然后执行该线程需要执行的业务逻辑, 那么run方法是怎么被执行的呢? Java线程和os线程 os ...
- ahjesus ubuntu10.4安装ruby2.1.1
sudo apt-get install python-software-properties sudo apt-add-repository ppa:brightbox/ruby-ng sudo a ...
- [js开源组件开发]js多选日期控件
js多选日期控件 详情请见:http://www.lovewebgames.com/jsmodule/calendar.html 它的github地址:https://github.com/tianx ...
- innerHtml and Jquery.html()
1. innerHtml是Dom HTML的属性 是只读的,不能写入. 2. JQuery只能调用.html(),它可以加参数,改变原HTML内容. http://api.jquery.com/htm ...
- Vue入门演示
工作中用了很久vue,但是都是我们这边前端经理封装好的组件,想要看到底部的原理还要从层层代码里面剥离出来,逻辑太复杂,还不如自己一点点整理一下,一步一步走下去. github地址:https://gi ...
- 【转】提高C#编程水平的50个要点
1.总是用属性 (Property) 来代替可访问的数据成员2.在 readonly 和 const 之间,优先使用 readonly3.在 as 和 强制类型转换之间,优先使用 as 操作符4.使用 ...
- RGui的http代理设置
办公电脑环境需要http代理访问大网,使用R语言安装包时老是无法连接网络,后来从网上发现解决方法很简单,只需在启动RGui.exe的命令行上加上启动参数就可以了. "C:\Program F ...
- 并查集(Disjoint Set)
在一些有N个元素的集合应用问题中,我们通常是在开始时让每个元素构成一个单元素的集合,然后按一定顺序将属于同一组的元素所在的集合合并,其间要反复查找一个元素在哪个集合中.这一类问题其特点是看似并不复杂, ...
- MyBatis入门(六)---mybatis与spring的整合
一.整合需要 1.1.方法 上一章中的数据 需要spring通过单例方式管理SqlSessionFactory spring和mybatis整合生成代理对象,使用SqlSessionFactory创建 ...
- IOS UICollectionView基础+UICollectionViewFlowLayout基础
UICollectionView在众多控件中也算是比较常用的了,像淘宝在浏览宝贝时采用的就是UICollectionView,对于UICollectionView->UICollectionVi ...