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 (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 312 Accepted Submission(s): 100
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.
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.
4
33A
2
33A
22
33
22
5559T
9993
Yes
No
Yes
Yes
Statistic | Submit | Discuss | Note
这题事实上就是斗地主,一道比較麻烦的模拟题,但假设分析好了事实上也不难。
我分情况进行讨论。
首先推断牌能否出完,然后推断炸弹,接着是1根,2根,3根,3带1,3带对,4带2,。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define CLR(A) memset(A,0,sizeof(A))
const int MAX=20;
char stra[MAX],strb[MAX];
int va[MAX],vb[MAX];
int na,nb;
void change(char s[],int v[]){
for(int i=0;i<strlen(s);i++){
if(s[i]>='3'&&s[i]<='9') v[i]=s[i]-'0';
if(s[i]=='T') v[i]=10;
if(s[i]=='J') v[i]=11;
if(s[i]=='Q') v[i]=12;
if(s[i]=='K') v[i]=13;
if(s[i]=='A') v[i]=14;
if(s[i]=='2') v[i]=15;
if(s[i]=='X') v[i]=16;
if(s[i]=='Y') v[i]=17;
}
}
int Bomb(int v[],int len){
int cnt=1,i;
for(i=len-1;i>=0;i--){
if(v[i]<16) break;
}
if(i<3) return 0;
i--;
for(;i>=0;i--){
if(v[i]==v[i+1])
cnt++;
else
cnt=1;
if(cnt==4) return v[i];
}
return 0;
} int Nuke(int v[],int len){
if(len<2) return 0;
if(v[len-1]==17&&v[len-2]==16) return 1;
return 0;
} int Pair(int v[],int len){
if(len<2) return 0;
for(int i=len-2;i>=0;i--){
if(v[i]==v[i+1]) return v[i];
}
return 0;
} int Trio(int v[],int len){
if(len<3) return 0;
int cnt=1;
for(int i=len-2;i>=0;i--){
if(v[i]==v[i+1]) cnt++;
else cnt=1;
if(cnt==3) return v[i];
}
return 0;
} int Trio_Solo(int v[],int len){
if(len<4) return 0;
int x=Trio(v,len);
if(x && x!=v[0] && x!=v[len-1])
return Trio(v,len);
} int Trio_Pair(int v[],int len){
if(len<5) return 0;
int x=Trio(v,len);
int pos;
if(x!=0){
pos=lower_bound(v,v+len,x)-v;
int t1=Pair(v,pos);
if(t1!=0) return x;
pos++;//防止溢出
for(pos;pos<len;pos++){
if(v[pos]!=v[pos-1]) break;
}
int t2=Pair(v+pos,len-pos);
if(t2!=0) return x;
}
return 0;
} int Four_Dual(int v[],int len){
if(len<6) return 0;
return Bomb(v,len);
} bool Drop_All(int v[],int len){
if(len>7) return false;
if(len==6&&Four_Dual(v,len)!=0) return 1;
if(len==5&&Trio_Pair(v,len)!=0) return 1;
if(len==4&&(Trio_Solo(v,len)!=0||Bomb(v,len)!=0)) return 1;
if(len==3&&Trio(v,len)!=0) return 1;
if(len==2&&Pair(v,len)!=0&&Nuke(v,len)) return 1;
if(len==1) return 1;
return 0;
} bool check(int v1[],int len1,int v2[],int len2){
int x,y;
if(Drop_All(v1,len1)) return true;
if(Nuke(v1,len1)!=0) return true;
if(Nuke(v2,len2)!=0) return false;
x=Bomb(v1,len1);y=Bomb(v2,len2);
if(x && y==0) return true;
if(x==0 && y) return false;
if(x && x>=y) return true;
if(y>x) return false;
if(v1[len1-1]>=v2[len2-1]) return true;
x=Pair(v1,len1);y=Pair(v2,len2);
if(x && x>=y) return true;
x=Trio(v1,len1);y=Trio(v2,len2);
if(x && x>=y) return true;
x=Trio_Solo(v1,len1);y=Trio_Solo(v2,len2);
if(x && x>=y) return true;
x=Trio_Pair(v1,len1);y=Trio_Pair(v2,len2);
if(x && x>=y) return true;
x=Four_Dual(v1,len1);y=Four_Dual(v2,len2);
if(x && x>=y) return true;
return false;
} int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%s%s",stra,strb);
na=strlen(stra);nb=strlen(strb);
change(stra,va);change(strb,vb);
sort(va,va+na);sort(vb,vb+nb);
if(check(va,na,vb,nb)) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6的更多相关文章
- HDU 4930 Fighting the Landlords(暴力枚举+模拟)
HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...
- HDU 4930 Fighting the Landlords(扯淡模拟题)
Fighting the Landlords 大意: 斗地主... . 分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black ...
- 2014多校第六场 1010 || HDU 4930 Fighting the Landlords (模拟)
题目链接 题意 : 玩斗地主,出一把,只要你这一把对方要不了或者你出这一把之后手里没牌了就算你赢. 思路 : 一开始看了第一段以为要出很多次,实际上只问了第一次你能不能赢或者能不能把牌出尽. #inc ...
- HDU 4930 Fighting the Landlords(模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 解题报告:斗地主,加了一个四张可以带两张不一样的牌,也可以带一对,判断打出一手牌之后,如果对手没 ...
- HDU 4930 Fighting the Landlords --多Trick,较复杂模拟
题意:两个人A和B在打牌,只有题目给出的几种牌能出若A第一次出牌B压不住或者A一次就把牌出完了,那么A赢,输出Yes,否则若A牌没出完而且被B压住了,那么A输,输出No. 解法:知道规则,看清题目,搞 ...
- HDU 6141 - I am your Father! | 2017 Multi-University Training Contest 8
思路来自 FXXL 最小树形图模板用kuangbin的 /* HDU 6141 - I am your Father! [ 最小树形图 ] | 2017 Multi-University Traini ...
- hdu 6406 Taotao Picks Apples (2018 Multi-University Training Contest 8 1010)(二分,前缀和)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6406 思路: 暴力,预处理三个前缀和:[1,n]桃子会被摘掉,1到当前点的最大值,1到当前点被摘掉的桃子的 ...
- hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3 A)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=6319 思路: 单调队列倒着维护,队列里面剩下的值的数量就是这一段区间的count值,如样例第一个区间:3 ...
- HDU 5775 Bubble Sort(线段树)(2016 Multi-University Training Contest 4 1012)
原址地址:http://ibupu.link/?id=31 Problem Description P is a permutation of the integers from 1 to N(ind ...
随机推荐
- mvc初学controller参数传递感想
从视图中传递参数给controller也有很多种方式 方法一(推荐):路由 config.Routes.MapHttpRoute( name: "DefaultApi", rout ...
- C# 创建Windows服务。服务功能:定时操作数据库 (转)
C# 创建Windows服务.服务功能:定时操作数据库 一.创建window服务 1.新建项目-->选择Windows服务.默认生成文件包括Program.cs,Service1.cs 2.在S ...
- FileSystemWatcher使用方法具体解释
FileSystemWatcher控件主要功能: 监控指定文件或文件夹的文件的创建.删除.修改.重命名等活动.能够动态地定义须要监控的文件类型及文件属性修改的类型. 1.经常使用的几个基本属性: (1 ...
- Hacker(14)----扫描目标计算机端口
端口是目前计算机与外界的通道,因而黑客一旦锁定目标计算机,便会扫描该计算机中已经开放的端口,从而得到更多的有用信息.扫描目标计算机端口一般使用SuperScan.X-Scan等. 一.端口扫描原理 扫 ...
- oracle安装、配置、卸载、错误解决
oracle安装卸载的帖子很多,这里整理出一份,都只是给出一个链接,忘了时可以自己看看.哈哈,其实我也觉得已经不会忘了,被这个鸡毛问题困了两天,修改控制文件.环境变量.注册表什么的都不能解决问题,最后 ...
- 利用IIS7 解决URL访问限制问题
网站可以通过URl直接访问一些不希望被访问的东西, 比如一些图片,js,css等等. 为了解决这个问题看了好多文章,不过毕竟我是新手菜鸟级别的,没有具体的解决方法,真心不知道怎么弄. 今天在看IIS的 ...
- 基于canvas图像处理的图片展示demo
图片展示网页往往色彩繁杂,当一个网页上有多张图片的时候用户的注意力就很不容易集中,而且会造成网站整个色调风格的不可把控. 能不能把所有的预览图变成灰度图片,等用户激活某张图片的时候再上色呢? 以前,唯 ...
- Linux中oracle的安装,亲测
一.下载oracle的软件包 地址: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-li ...
- 如何更改 Mac OS X 系统默认用户名
说到 Mac 用户名估计有许多人都不知道在哪个地方修改,其实说简单也简单说麻烦也麻烦看你自己的需求.好比如果你只要用户名的登录更改,那是就非常简单的事了.下面这里就给大家介绍mac osx系统如何更改 ...
- Java IO5:管道流、对象流
前言 前面的文章主要讲了文件字符输入流FileWriter.文件字符输出流FileReader.文件字节输出流FileOutputStream.文件字节输入流FileInputStream,这些都是常 ...