Fighting the Landlords

Fighting the Landlords

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 175    Accepted Submission(s): 61

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
(i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q
(Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5
> 4 > 3. It’s the basic rank of cards.

2.Pair : two
matching cards of equal rank (e.g. 3-3, 4-4, 2-2 etc.). Note that the
two Jokers cannot form a Pair (it’s another category of cards). The
comparison is based on the rank of Solo, where 2-2 is the highest, A-A
comes second, and 3-3 is the lowest.

3.Trio: three cards of
the same rank (e.g. 3-3-3, J-J-J etc.). The priority is similar to the
two categories above: 2-2-2 > A-A-A > K-K-K > . . . > 3-3-3.

4.Trio-Solo: three cards of the same rank with a Solo as the kicker.
Note that the Solo and the Trio should be different rank of cards (e.g.
3-3-3-A, 4-4-4-X etc.). Here, the Kicker’s rank is irrelevant to the comparison, and the Trio’s rank determines the priority. For example, 4-4-4-3 > 3-3-3-2.

5.Trio-Pair : three cards of the same rank with a Pair as the kicker
(e.g. 3-3- 3-2-2, J-J-J-Q-Q etc.). The comparison is as the same as
Trio-Solo, where the Trio is the only factor to be considered. For
example,4-4-4-5-5 > 3-3-3-2-2. Note again, that two jokers cannot
form a Pair.

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
of the same category but not the others. For example, only a prior Solo
can beat a Solo while a Pair cannot. But there’re exceptions:

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
except Nuke or another Bomb with a higher rank. The rank of Bombs
follows the rank of individual cards: 2-2-2-2 is the highest and 3-3-3-3
is the lowest.

Given the cards of both yours and the next
player’s, please judge whether you have a way to play a hand of cards
that the next player cannot beat you in this round. If you no longer have cards after playing, we consider that he cannot beat you either. You may see the sample for more details.

 
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
indicating your cards and the next player’s, respectively. The length of
each string doesn’t exceed 17, and each single card will occur at most 4 times totally on two players’ hands except that the two Jokers each occurs only once.

 
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 模拟的更多相关文章

  1. hdu4930 Fighting the Landlords(模拟 多校6)

    题目链接:pid=4930">http://acm.hdu.edu.cn/showproblem.php? pid=4930 Fighting the Landlords Time L ...

  2. HDU-4930 Fighting the Landlords 多校训练赛斗地主

    仅仅须要推断一个回合就能够了,枚举推断能够一次出全然部牌或者大过对面的牌的可能,注意的是4张同样的牌带两张牌的话是能够被炸弹炸的. #include <iostream> #include ...

  3. HDU 4930 Fighting the Landlords(扯淡模拟题)

    Fighting the Landlords 大意: 斗地主... . 分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black ...

  4. HDU 4930 Fighting the Landlords(暴力枚举+模拟)

    HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...

  5. HDU 4930 Fighting the Landlords --多Trick,较复杂模拟

    题意:两个人A和B在打牌,只有题目给出的几种牌能出若A第一次出牌B压不住或者A一次就把牌出完了,那么A赢,输出Yes,否则若A牌没出完而且被B压住了,那么A输,输出No. 解法:知道规则,看清题目,搞 ...

  6. HDU 4930 Fighting the Landlords(模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 解题报告:斗地主,加了一个四张可以带两张不一样的牌,也可以带一对,判断打出一手牌之后,如果对手没 ...

  7. 2014多校第六场 1010 || HDU 4930 Fighting the Landlords (模拟)

    题目链接 题意 : 玩斗地主,出一把,只要你这一把对方要不了或者你出这一把之后手里没牌了就算你赢. 思路 : 一开始看了第一段以为要出很多次,实际上只问了第一次你能不能赢或者能不能把牌出尽. #inc ...

  8. 2014 多校联合训练赛6 Fighting the Landlords

    本场比赛的三个水题之一,题意是两个玩家每人都持有一手牌,问第一个玩家是否有一种出牌方法使得在第一回和对方无牌可出.直接模拟即可,注意一次出完的情况,一开始没主意,wa了一发. #include< ...

  9. 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 ...

随机推荐

  1. 51nod平均数

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  2. WPF弹出取消确定框

    MessageBoxResult dr = MessageBox.Show("是否在"+ConfigHelper.GetAppSetting("SourceDBName& ...

  3. CodeForces 209C Trails and Glades

    C. Trails and Glades time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  4. struts2 CVE-2013-1965 S2-012 Showcase app vulnerability allows remote command execution

    catalog . Description . Effected Scope . Exploit Analysis . Principle Of Vulnerability . Patch Fix 1 ...

  5. Fckeditor PHP/ASP File Upload Vul

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 FCKeditor是目前最优秀的可见即可得网页编辑器之一,它采用JavaScrip ...

  6. linux系统安装配置

    以中文拼音输入法为例:1.sudo apt install ibus-pinyin2.sudo apt install ibus-libpinyin3.注销重新登录 或则 重启计算机4.进入输入设置, ...

  7. MVC5-7 ValueProvider

    统一的数据获取 在WebForm时代,我们是怎么获取值的呢? HttpContext.Request.QueryString HttpContext.Request.Form HttpContext. ...

  8. 系统配置 之:远程桌面连接(win7系统)

    本文包括两部分: 1.配置远程桌面连接 2.解决[远程桌面连接不上] 一.远程桌面连接设置 [远程桌面连接配置] Win7系统下的远程桌面连接设置,如果是其他系统或 Win8 及其以上系统,也可作为参 ...

  9. 第三次作业——个人作业,k米案例分析

    第一部分 调研,评测 评测 1.下载并使用 第一次打开,没什么很深的印象,看见"扫一扫",随手就点了,然后就出现了严重的卡顿,大概是刚启动并且第一次启动的原因,后面就还好了.而且第 ...

  10. Alpha版本十天冲刺——Day 7

    站立式会议 祝曹鑫杰和常松童鞋生日快乐!短短几天冲刺,就迎来了三位队员的生日,希望也给我们的Alpha版本带来好运,加油! 会议总结 队员 今天完成 遇到的问题 明天要做 感想 鲍亮 上传图片接口 无 ...