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 ...
随机推荐
- 【BZOJ-1576】安全路径Travel Dijkstra + 并查集
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1044 Solved: 363[Sub ...
- ecshop /includes/init.php Arbitrary User Login Vul
catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 对用户输入的cookie,判断免登的逻辑中存在漏洞,导致黑客可以直接通过 ...
- Scala: 包对象
包对象最重要的用途是兼容旧的类库,或者为某些数据类型提供增强版本:一般我们可以将其作为扩展工具方法或数据来使用
- java.io.IOException: No FileSystem for scheme: hdfs
在这篇文章中,介绍了如何将Maven依赖的包一起打包进jar包.使用maven-assembly打成jar后,将这个jar提供给其他工程引用的时候,报出如下错误: log4j:WARN No appe ...
- 加州大学伯克利分校Stat2.2x Probability 概率初步学习笔记: Section 2 Random sampling with and without replacement
Stat2.2x Probability(概率)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...
- POJ1050To the Max(求最大子矩阵)
题目链接 题意:给出N*N的矩阵,求一个子矩阵使得子矩阵中元素和最大 分析: 必备知识:求一组数的最大连续和 int a[N]; ,maxn = -INF; ; i <= n; i++) { i ...
- 利用 Django REST framework 编写 RESTful API
利用 Django REST framework 编写 RESTful API Updateat 2015/12/3: 增加 filter 最近在玩 Django,不得不说 rest_framewor ...
- sql附加数据库错误5120
http://zhidao.baidu.com/link?url=p1o8EjUhn-RYFt1D4uIM-5HQF1oXZIRlPGaDiZ2FRMDzZDG1ooSARfkoPWG6SzTJTN6 ...
- xfce4 dev tools的一些说明
xfce4 dev tools实际上基本是封装了一些autoconf的宏函数 比如XDT_I18N: AC_DEFUN([XDT_I18N], [ dnl Substitute GETTEXT_PAC ...
- 适可而止:YAGNI原则
适可而止:You Ain't Gonna Need It YAGNI原则指的是只需要将应用程序必需的功能包含进来,而不要试图添加任何其他你认为可能需要的功能. 在一个软件项目中,往往80%的时间花费在 ...