hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6
-- The HDU 2014 multi Contest Training University
2023-09-27 14:27:04 时间
题目链接: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
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.
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.
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
这题事实上就是斗地主,一道比較麻烦的模拟题,但假设分析好了事实上也不难。
我分情况进行讨论。
首先推断牌能否出完,然后推断炸弹,接着是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; }
相关文章
- (转载)How browsers work--Behind the scenes of modern web browsers (前端必读)
- 7 -- Spring的基本用法 -- 12... Spring 3.0 提供的表达式语言(SpEL)
- 第十六届全国大学生智能汽车竞赛--百度智慧交通(东部赛区)
- Andrew Ng -- What is Ai? the third week
- Andrew Ng -- What is Ai? the first week
- The "Go" Learning Trip -- 1. Hello Go, Frist “go” Code -- Part1-1
- English trip -- VC(情景课)10 B Around the house 在家里
- English trip -- VC(情景课)4 B Parts of the body 身体部位
- 并发编程--理解JAVA中的各种锁
- yocto编译时报错"fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead"如何处理?
- 【前端开发】Webpack electron打包--ValidationError: Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema
- 音频处理贤内助--libsndfile
- android -- 蓝牙 bluetooth (二) 打开蓝牙
- css- 选择器-背景--文本--字体--链接
- What is the difference between Reactjs and Rxjs?--React is the V (View) in MVC (Model/View/Controller).
- CentOS7系列--10.1CentOS7中的GNOME桌面环境
- wp api jwt 403 (Forbidden) -- JWT is not configurated properly, please contact the admin
- (未完毕)电子设计省赛--2013年国赛题
- 《C#零基础入门之百识百例》(九十六)本地数据交互 -- 读写Excel表格文件
- USACO--2.1The Castle
- 非常好的web弹出层框架 -- layer
- c语言开源项目--SQLite学习资料总结
- Zuul 2 : The Netflix Journey to Asynchronous, Non-Blocking Systems--转
- Inversion of Control Containers and the Dependency Injection pattern--Martin Fowler
- Writing Images to the Excel Sheet using PHPExcel--转载
- The LMAX disruptor Architecture--转载
- Java 下实现锁无关数据结构--转载
- Hibernate: Truly Understanding the Second-Level and Query Caches--reference
- Implementing the skip list data structure in java --reference
- Basic Data Structures and Algorithms in the Linux Kernel--reference
- asp webForm 三层框架的简单实例(一)未完待续--