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.
InputThe input contains several test cases. The number of test cases T (T<=20) occurs in the first line of input.
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. OutputFor each test case, output Yes if you can reach your goal, otherwise output No. Sample Input
4 33A 2 33A 22 33 22 5559T 9993Sample Output
Yes No Yes Yes
判断在这一次出牌时,用手中的牌是否可以压制对手;
模拟斗地主,
1、谁有王炸谁赢
2、我有炸弹,比对方大 赢
3、我有的牌,对方没有,或我的比对方大 赢
4、我一次性出完,赢
其他为输。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int flag1[10000];
int flag2[10000];
int hs[10000];
string s1,s2;
vector <int> a1,a2,a3,a4,a5,a6,a7,a8;
vector <int> b1,b2,b3,b4,b5,b6,b7,b8;
void init()
{
memset(flag1,0,sizeof(flag1));
memset(flag2,0,sizeof(flag2));
a1.clear();
a2.clear();
a3.clear();
a4.clear();
a5.clear();
a6.clear();
a7.clear();
a8.clear();
b1.clear();
b2.clear();
b3.clear();
b4.clear();
b5.clear();
b6.clear();
b7.clear();
b8.clear();
}
int main()
{
int T;
cin >> T;
hs['3'] = 0;
hs['4'] = 1;
hs['5'] = 2;
hs['6'] = 3;
hs['7'] = 4;
hs['8'] = 5;
hs['9'] = 6;
hs['T'] = 7;
hs['J'] = 8;
hs['Q'] = 9;
hs['K'] = 10;
hs['A'] = 11;
hs['2'] = 12;
hs['X'] = 13;
hs['Y'] = 14;
while(T--)
{
init();
cin >> s1>>s2;
for(int i=0;i<s1.size();i++)
{
flag1[hs[s1[i]]]++;
}
for(int i=0;i<s2.size();i++)
{
flag2[hs[s2[i]]]++;
}
for(int i=0;i<=14;i++)//单张
{
if(flag1[i]==1)
{
a1.push_back(i);
}
}
for(int i=0;i<=14;i++)//对子
{
if(flag1[i]==2)
{
a2.push_back(i);
}
}
for(int i=0;i<=14;i++)//三张
{
if(flag1[i]==3)
{
a3.push_back(i);
}
}
for(int i=0;i<=14;i++)
{
if(flag1[i]==4)
{
a4.push_back(i);
}
}
for(int i=0;i<=14;i++)
{
if(flag2[i]==4)
{
b4.push_back(i);
}
}
a5.push_back(-1);
b5.push_back(0);
for(int i=0;i<=14;i++)//对子
{
if(flag1[i]>=2)
{
a5.push_back(i);
}
}
for(int i=0;i<=14;i++)
{
if(flag2[i]>=2)
{
b5.push_back(i);
}
}
a6.push_back(-1);
b6.push_back(0);
for(int i=0;i<=14;i++)//三张
{
if(flag1[i]>=3)
{
a6.push_back(i);
}
}
for(int i=0;i<=14;i++)
{
if(flag2[i]>=3)
{
b6.push_back(i);
}
}
a7.push_back(-1);
b7.push_back(0);
for(int i=0;i<=14;i++)//四张
{
if(flag1[i]==4)
{
a7.push_back(i);
}
}
for(int i=0;i<=14;i++)
{
if(flag2[i]==4)
{
b7.push_back(i);
}
}
a8.push_back(-1);
b8.push_back(0);
for(int i=0;i<=14;i++)//单张
{
if(flag1[i]>=1)
{
a8.push_back(i);
}
}
for(int i=0;i<=14;i++)
{
if(flag2[i]>=1)
{
b8.push_back(i);
}
}
if(s1.size()==1||a2.size()==1&&s1.size()==2||
a3.size()==1&&s1.size()==3||
a4.size()==1&&s1.size()==4||
a3.size()==1&&a1.size()==1&&s1.size()==4||
a3.size()==1&&a2.size()==1&&s1.size()==5||
a4.size()==1&&a1.size()==2&&s1.size()==6||
a4.size()==1&&a2.size()==1&&s1.size()==6
)//一次出完
{
cout << "Yes"<<endl;
continue;
}
if(flag1[13]==1&&flag1[14]==1)
{
cout << "Yes"<<endl;
continue;
}
if(flag2[13]==1&&flag2[14]==1)
{
cout << "No"<<endl;
continue;
}
if(b4.size()>0)
{
cout << "No"<<endl;
continue;
}
if(a8[a8.size()-1]>=b8[b8.size()-1])
{
cout << "Yes"<<endl;
continue;
}
if(a5[a5.size()-1]>=b5[b5.size()-1])
{
cout << "Yes"<<endl;
continue;
}
if(a6[a6.size()-1]>=b6[b6.size()-1])
{
cout << "Yes"<<endl;
continue;
}
if(a7[a7.size()-1]>=b7[b7.size()-1])
{
cout << "Yes"<<endl;
continue;
}
cout << "No"<<endl;
}
return 0;
}