HDU4930 Fighting the Landlords 模拟
Fighting the LandlordsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Problem Description
Fighting the Landlords is a card game which has been a heat for years
in China. The game goes with the 54 poker cards for 3 players, where the “Landlord” has 20 cards and the other two (the “Farmers”) have 17. The Landlord wins if he/she has no cards left, and the farmer team wins if either of the Farmer have no cards left. The game uses the concept of hands, and some fundamental rules are used to compare the cards. For convenience, here we only consider the following categories of cards: 1.Solo: a single card. The priority is: Y (i.e. colored Joker) > X 2.Pair : two 3.Trio: three cards of 4.Trio-Solo: three cards of the same rank with a Solo as the kicker. 5.Trio-Pair : three cards of the same rank with a Pair as the kicker 6.Four-Dual: four cards of the same rank with two cards as the kicker. Here, it’s allowed for the two kickers to share the same rank. The four same cards dominates the comparison: 5-5-5-5-3-4 > 4-4-4-4-2-2. In the categories above, a player can only beat the prior hand using 7.Nuke: X-Y (JOKER-joker). It can beat everything in the game. 8.Bomb: 4 cards of the same rank. It can beat any other category Given the cards of both yours and the next Input
The input contains several test cases. The number of test cases T (T<=20) occurs in the first line of input.
Each test case consists of two lines. Both of them contain a string Output
For each test case, output Yes if you can reach your goal, otherwise output No.
Sample Input
4
33A 2 33A 22 33 22 5559T 9993 Sample Output
Yes
No Yes Yes Source
Recommend
hujie
|
题意:斗地主。给你两个人手上的牌,现在轮到自己出,若自己能一次出完或者自己出的这一发对方没法接,则输出Yes,否则输出No。除了王每种牌还有4张,大王小王各一张。出牌方式有单牌、对子、3个、3带1、3带2、4带2、王炸、炸弹。
题解:模拟。
这个模拟比较复杂,我们可以通过充分利用函数来降低编程难度、增加程序可读性。
先把自己手牌读进字符串s1里,长度len1=strlen(s1),
调用函数void attack(const char s[20],const int &len,int h[20],int hh[6]),得到h1和hh1,h1[i]表示数值为i的牌有多少张(T为10,J为11,……,小王X为16,大王Y为17,这里可以有很多方法把字母和数字对应上),hh1[j]表示数值为j的h1[i]有多少个,即统计炸弹数量hh1[4]、三个数量hh1[3]、对子数量hh1[2]、单牌数量hh1[1]。
通过h1和hh1,我们可以很容易地判断能不能一下出完牌,像这样:
///全出完
//cout<<hh1[1]<<','<<hh1[2]<<','<<hh1[3]<<','<<hh1[4]<<endl;
if(h1[]== && h1[]== && len1==)return ;///王炸
if(hh1[]== && len1==)return ;///4带2
if(hh1[]== && len1==)return ;///炸弹
else if(hh1[]== && hh1[]== && ( (len1==) || (len1== && hh1[]==) || (len1== && hh1[]==) ))return ;///3个、3带1、3带2
else if(hh1[]== && hh1[]== && hh1[]== && hh1[]== && len1==)return ;///一对
else if(len1==)return ;///一张
一次出完牌的情况
接下来我们要判断一次出不完的时候,自己出什么牌能让对方无牌可接。
对对手的手牌s2调用attack,得到h2和hh2。
为了方便比较相同种类的牌谁的比较大,我们新写一个函数int MaxCard(int h[20],int hh[6],int len,int x,int y),返回值为用h和hh表示的牌组成(x带y)(例如3带2、4带0)的x的最大值,若牌组不成x带y,则返回-1。这个函数很好写,啪啪啪就能写出来。
然后,我们先用h1和h2从王炸开始判断,我有王炸我就碉,他有王炸我就萎,判完王炸再判其他的。
判4个组成的炸弹,
if(MaxCard(h1,hh1,len1,,)<MaxCard(h2,hh2,len2,,))return ;///炸弹没它大 或者 自己没炸弹他有炸弹
else if(MaxCard(h1,hh1,len1,,)>MaxCard(h2,hh2,len2,,))return ;///炸弹比它大 或者 它没炸弹我有炸弹
判炸弹
接下来是没炸弹的情况,从3带2、3带1、3个、一对、1个依次判下去,若我有这种牌组,我的这个牌组的MaxCard数值不小于他的这个牌组的MaxCard数值,则碉。如果全判完了还不碉,就萎。
if(MaxCard(h1,hh1,len1,,)!=- && MaxCard(h1,hh1,len1,,)>=MaxCard(h2,hh2,len2,,))return ;
if(MaxCard(h1,hh1,len1,,)!=- && MaxCard(h1,hh1,len1,,)>=MaxCard(h2,hh2,len2,,))return ;
if(MaxCard(h1,hh1,len1,,)!=- && MaxCard(h1,hh1,len1,,)>=MaxCard(h2,hh2,len2,,))return ;
if(MaxCard(h1,hh1,len1,,)!=- && MaxCard(h1,hh1,len1,,)>=MaxCard(h2,hh2,len2,,))return ;
if(MaxCard(h1,hh1,len1,,)!=- && MaxCard(h1,hh1,len1,,)>=MaxCard(h2,hh2,len2,,))return ;
return ;
就是这样,怒考虑好所有情况就能A。我当时多考虑了一个4带1,结果居然没有这种情况,看来我对斗地主的理解还不够深。经过队友further大神的指点过了这题,真不容易。
全代码:
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll __int64
#define usint unsigned int
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,x,n) for(int i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1.out","w",stdout) char s1[],s2[];
int len1,len2;
int v[];
int h1[],h2[],hh1[],hh2[]; void attack(const char s[],const int &len,int h[],int hh[])
{
for(int i=;i<len;i++)
h[v[s[i]]]++;
// for(int i=0;i<20;i++)
// cout<<h[i]<<' ';
// puts("");
for(int i=;i<;i++)
hh[h[i]]++;
} int MaxCard(int h[],int hh[],int len,int x,int y)
{
if(x== && hh[]==)return -;
if(x== && hh[]+hh[]==)return -;
if(x== && hh[]+hh[]+hh[]==)return -;
if(len==)return -;
int ma=;
for(int i=;i>=;i--)
{
//cout<<i<<'.'<<h[i]<<' ';
if(h[i]>=x) {ma=i;break;}
}
//printf("(%d,%d,%d)break!\n",x,y,ma);
if(x==)return ma;///炸弹
if(x== && y==)return ma;///三带0
if(x== && y== && (hh[]+hh[]+hh[]>=))return ma;///三带2
if(x== && y== && len>=) return ma;///三带1
if(x==)return ma;///一对
if(x==)return ma;///一张
return -;
} bool gank()
{
if(len1==)return ;
mz(h1);mz(hh1);
attack(s1,len1,h1,hh1);
///全出完
//cout<<hh1[1]<<','<<hh1[2]<<','<<hh1[3]<<','<<hh1[4]<<endl;
if(h1[]== && h1[]== && len1==)return ;///王炸
if(hh1[]== && len1==)return ;///4带2
if(hh1[]== && len1==)return ;///炸弹
else if(hh1[]== && hh1[]== && ( (len1==) || (len1== && hh1[]==) || (len1== && hh1[]==) ))return ;///3个、3带1、3带2
else if(hh1[]== && hh1[]== && hh1[]== && hh1[]== && len1==)return ;///一对
else if(len1==)return ;///一张 ///一下出不完的
mz(h2);mz(hh2);
attack(s2,len2,h2,hh2);
if(h2[]>= && h2[]>=) return ;///被王炸
if(h1[]>= && h1[]>=) return ;///王炸
if(MaxCard(h1,hh1,len1,,)<MaxCard(h2,hh2,len2,,))return ;///炸弹没它大 或者 自己没炸弹他有炸弹
else if(MaxCard(h1,hh1,len1,,)>MaxCard(h2,hh2,len2,,))return ;///炸弹比它大 或者 它没炸弹我有炸弹
///下面是都没炸弹的
//printf("h1:%d,h2:%d\n",MaxCard(h1,hh1,len1,3,2),MaxCard(h2,hh2,len2,3,2));
if(MaxCard(h1,hh1,len1,,)!=- && MaxCard(h1,hh1,len1,,)>=MaxCard(h2,hh2,len2,,))return ;
if(MaxCard(h1,hh1,len1,,)!=- && MaxCard(h1,hh1,len1,,)>=MaxCard(h2,hh2,len2,,))return ;
if(MaxCard(h1,hh1,len1,,)!=- && MaxCard(h1,hh1,len1,,)>=MaxCard(h2,hh2,len2,,))return ;
if(MaxCard(h1,hh1,len1,,)!=- && MaxCard(h1,hh1,len1,,)>=MaxCard(h2,hh2,len2,,))return ;
if(MaxCard(h1,hh1,len1,,)!=- && MaxCard(h1,hh1,len1,,)>=MaxCard(h2,hh2,len2,,))return ;
return ;
} int main()
{
int T,i,j,k;
v['Y']=;
v['X']=;
v['']=;
v['A']=;
v['K']=;
v['Q']=;
v['J']=;
v['T']=;
for(i=;i<=;i++)
v[''+i]=i;
scanf("%d\n",&T);
while(T--)
{
gets(s1);
gets(s2);
len1=strlen(s1);
len2=strlen(s2);
//sort(s1,s1+len1,cmp);
//sort(s2,s2+len2,cmp);
// puts(s1);
// puts(s2);
if(gank()) puts("Yes");
else puts("No");
}
return ;
}
HDU4930 Fighting the Landlords 模拟的更多相关文章
- hdu4930 Fighting the Landlords(模拟 多校6)
题目链接:pid=4930">http://acm.hdu.edu.cn/showproblem.php? pid=4930 Fighting the Landlords Time L ...
- HDU-4930 Fighting the Landlords 多校训练赛斗地主
仅仅须要推断一个回合就能够了,枚举推断能够一次出全然部牌或者大过对面的牌的可能,注意的是4张同样的牌带两张牌的话是能够被炸弹炸的. #include <iostream> #include ...
- HDU 4930 Fighting the Landlords(扯淡模拟题)
Fighting the Landlords 大意: 斗地主... . 分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black ...
- HDU 4930 Fighting the Landlords(暴力枚举+模拟)
HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...
- HDU 4930 Fighting the Landlords --多Trick,较复杂模拟
题意:两个人A和B在打牌,只有题目给出的几种牌能出若A第一次出牌B压不住或者A一次就把牌出完了,那么A赢,输出Yes,否则若A牌没出完而且被B压住了,那么A输,输出No. 解法:知道规则,看清题目,搞 ...
- HDU 4930 Fighting the Landlords(模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 解题报告:斗地主,加了一个四张可以带两张不一样的牌,也可以带一对,判断打出一手牌之后,如果对手没 ...
- 2014多校第六场 1010 || HDU 4930 Fighting the Landlords (模拟)
题目链接 题意 : 玩斗地主,出一把,只要你这一把对方要不了或者你出这一把之后手里没牌了就算你赢. 思路 : 一开始看了第一段以为要出很多次,实际上只问了第一次你能不能赢或者能不能把牌出尽. #inc ...
- 2014 多校联合训练赛6 Fighting the Landlords
本场比赛的三个水题之一,题意是两个玩家每人都持有一手牌,问第一个玩家是否有一种出牌方法使得在第一回和对方无牌可出.直接模拟即可,注意一次出完的情况,一开始没主意,wa了一发. #include< ...
- hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...
随机推荐
- HA模式手动切换namenode状态
查看状态 hdfs haadmin -getServiceState nn1 有时候通过网页访问两个namenode的http-address,看到默认的主namenode状态变成了standy,这时 ...
- BZOJ4720 [Noip2016]换教室
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...
- BZOJ2301 [HAOI2011]Problem b
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...
- 使用Wireshark 抓取数据包
Wireshark 是一个网络封包分析软件.网络封包分析软件的功能是获取网络封包,并尽可能显示出最为详细的网络封包资料.Wireshark使用WinPCAP作为接口,直接与网卡进行数据报文交换. 一 ...
- 高可用与负载均衡(1)之linux系统的数据链路层负载均衡
preface 在蓝厂就职到时候,每台缓存服务器都能够跑到2G的流量,这么大的流量,有人会问,服务器是不是安装的万兆网卡,no no no,仅仅是3张千兆网卡绑定在一块.万兆网卡的服务器少见,大多数都 ...
- python 培训之 Python 数据类型
0. 变量 计算机某块内存的标签,存储数据的容器的标签,可被覆盖. a = "" a = "a1bcd" a=a+"ddd&quo ...
- 【原】http缓存与cdn相关技术
摘要:最近要做这个主题的组内分享,所以准备了一个星期,查了比较多的资料.准备的过程虽然很烦很耗时间,不过因为需要查很多的资料,因此整个过程下来,对这方面的知识影响更加深刻.来来来,接下来总结总结 一 ...
- Navicat 的使用(一)
1.创建连接 主机名 : 可以不写名称随意 主机名/IP地址:localhost或者127.0.0.1 都是本机的意思 端口:默认3306 尽量不要改怕与其余端口重复,如有重名端口系统会报错 用户 ...
- CentOS7安装Ambari
环境: CentOS7安装两个节点:master.slave1.并配置ssh无密码登录. 步骤: 获取 Ambari 的公共库文件(public repository): wget http://pu ...
- Centos7安装Oracle12c
环境: CentOS7@VMware12,分配资源:CPU:2颗,内存:4GB,硬盘空间:30GB Oracle12C企业版64位 过程纪要: root身份安装依赖包: compat-libstdc+ ...