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 ...
随机推荐
- 【faster-rcnn】训练自己的数据——修改图片格式、类别
修改图片格式 matlab代码 其实内部一些代码是用了rbg的fast-rcnn代码的. \datasets\VOCdevkit2007\VOCcode\VOCinit.m里面,查找'jpg',改成' ...
- 【BZOJ-4636】蒟蒻的数列 动态开点线段树 ||(离散化) + 标记永久化
4636: 蒟蒻的数列 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 247 Solved: 113[Submit][Status][Discuss ...
- Refresh和Invalidate的比较
Refresh: 强制控件使其工作区无效并立即重绘自己和任何子控件.==Invalidate + Update Invalidate: 使控件的特定区域(可以自己设置区域,从而提高性能)无效并向控件发 ...
- Linux 吃掉我的内存
在Windows下资源管理器查看内存使用的情况,如果使用率达到80%以上,再运行大程序就能感觉到系统不流畅了,因为在内存紧缺的情况下使用交换分区,频繁地从磁盘上换入换出页会极大地影响系统的性能.而当我 ...
- 高可用与负载均衡(8)之聊聊 LVS重要参数和优化以及监控
preface 在明白LVS-DR模式的部署之后,我们看看LVS的几个重要参数: 如有问题,请联系我18500777133@sina.cn [root@localhost ~]# ls /proc/s ...
- ubuntu --- shortcut key
Linux系统下图形界面与Linux命令行模式的切换的方法 由图形转换到控制台模式:ctrl+alt+f1~f6(同时按下3秒钟不要马上松开)....由控制台转向图形模式是:alt+f7 快捷键(ub ...
- hibernate----(Hql)查询
package com.etc.test; import java.util.List;import java.util.Properties; import org.hibernate.Query; ...
- cobbler深入学习
cobbler重要目录和cobbler各对象的关系 /var/www/cobbler/ks_mirror 存放操作系统镜像/var/www/cobbler/repo_mirror 存放仓库镜像/var ...
- 什么是jsonp
Jsonp其实就是一个跨域解决方案. Js跨域请求数据是不可以的,但是js跨域请求js脚本是可以的. 所以可以把要请求的数据封装成一个js语句,做一个方法的调用. 跨域请求js脚本可以得到此脚本.得到 ...
- linux认识第一面
一.领域问题: 在客户端领域,windows始终占据了优势地位.而在服务器领域,全球98%的都是在用linux.因为linux作为服务器的载体,便宜又安全. 二.linux是基于内核的编写工具,在li ...