Fighting the Landlords HDU - 4930

Fighting the Landlords HDU - 4930

题目描述
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.

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.

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

大致题意
就是你手里有一副牌,对面手里也有一副牌,现在你出牌,如果你能把手中的牌一次性打完或者你出的牌对面接不上就输出yes 否则 no

思路
模拟乱搞,题意一定要看清,有哪些是可行的打法,比如三带一,三带二,四带二,四个头的炸弹,大王小王一起是最大的炸弹。3是最小的牌等等。。
坑点:不能四带一,大王不能变牌(我一直以为斗地主里大王也能变牌,然后这题就一直错了。。。直到测试数据时yuhai同学无意间给了我一个带大王的数据。。。哭死)

下面是丑陋的代码。。

#include <iostream> 
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include<sstream>
#include<ctime>
using namespace std;  

int main()  
{  
   int n,l1,l2,d,s,sa,flag,x;
   char s1[100],s2[100];
   int  a1[20],a2[20],p1[5],p2[5],f1,f2;
   cin>>n;
   getchar();
   while(n--)
   {
        memset(a1,0,sizeof(a1));    
        memset(a2,0,sizeof(a2));
        memset(p1,0,sizeof(p1));
        memset(p2,0,sizeof(p2));
        flag=sa=d=s=f1=f2=0;      //初始化
        gets(s1);    
        gets(s2);    //输入两幅牌               
        l1=strlen(s1);
     for(int i=0;i<l1;i++)
     {
        if(s1[i]>='3'&&s1[i]<='9')
        {
            a1[s1[i]-'0']++;
        }
        else if(s1[i]=='T') a1[10]++;
        else if(s1[i]=='J') a1[11]++;
        else if(s1[i]=='Q') a1[12]++;
        else if(s1[i]=='K') a1[13]++;
        else if(s1[i]=='A') a1[14]++; 
        else if(s1[i]=='2') a1[15]++;
        else if(s1[i]=='X') a1[16]++;
        else if(s1[i]=='Y') a1[17]++;  //判断每张牌出现的次数
    }
   if(a1[16]==1&&a1[17]==1) p1[2]=17; 
    for(int i=17;i>=3;i--)
    {
        if(a1[i]!=0)
        {
             x=a1[i];
             if(a1[i]==1) d++;  //判断单张牌出现的次数
             if(a1[i]==2) s++;  //判断两张牌出现的次数
             if(a1[i]==3) sa++; // 判断三张牌出现的次数
             p1[a1[i]]=max(p1[a1[i]],i); 
             while(x)  //多的牌可以拆成小的牌打,比如222可以拆成22或者2打出
             {
                 p1[x]=max(p1[x],i);
                 x--;
             }
             //比较单,双,三,炸弹的最大牌面。用数组p1/p2记录
         }  
     }
     l2=strlen(s2);   //同理处理对方的牌
     for(int i=0;i<l2;i++)
     {
        if(s2[i]>='3'&&s2[i]<='9')
        {
            a2[s2[i]-'0']++;
        }
        else if(s2[i]=='T') a2[10]++;
        else if(s2[i]=='J') a2[11]++;
        else if(s2[i]=='Q') a2[12]++;
        else if(s2[i]=='K') a2[13]++;
        else if(s2[i]=='A') a2[14]++; 
        else if(s2[i]=='2') a2[15]++;
        else if(s2[i]=='X') a2[16]++;
        else if(s2[i]=='Y') a2[17]++;

    }
   if(a2[16]==1&&a2[17]==1) p2[2]=17;   
    for(int i=17;i>=3;i--)
    {
        if(a2[i]!=0)
        {
             x=a2[i];
             p2[a2[i]]=max(p2[a2[i]],i);
             while(x)
             {
               p2[x]=max(p2[x],i);
               x--;
             }
        }  
    }

     if(p2[4]==0&&(a2[17]==0||a2[16]==0))//如果对方没炸弹,则我们只要有一种方式的牌面大于对面就赢,单张,双张。。
     {
        if((p1[1]>=p2[1]&&p1[1]!=0)||(p1[2]>=p2[2]&&p1[2]!=0)||(p1[3]>=p2[3]&&p1[3]!=0)||(p1[4]>=p2[4]&&p1[4]!=0)||(l1==1))
        {
          flag=1;
        }
        else // 或者能一口气打完也赢
        {
          if(l1==2&&p1[2]>0)    
          flag=1;
          if(l1==3&&p1[3]>0) 
          flag=1;
          if(l1==4&&(p1[3]>0||p1[4]>0)) 
          flag=1;
          if(l1==5&&p1[3]>0)    
          flag=1;
          if(l1==6&&p1[4]>0) 
          flag=1;
        }
     }
     else //对面有炸弹
     {
        if(a1[17]==1&&a1[16]==1) flag=1; //我方有王炸
        if(p1[4]>=p2[4]&&(a2[17]!=1||a2[16]!=1))  //我们的炸弹面值大于对面
        flag=1;
        if(a2[17]==1&&a2[16]==1) //或者能一口气打完
        {
           if(l1==2&&p1[2]>0)   
          flag=1;
          if(l1==3&&p1[3]>0) 
          flag=1;
          if(l1==4&&(p1[3]>0||p1[4]>0)) 
          flag=1;
          if(l1==5&&p1[3]>0)    
          flag=1;
          if(l1==6&&p1[4]>0) 
          flag=1;       
        }
     }
     if(flag==1) cout<<"Yes\n"; //输出答案
     else cout<<"No\n";
    }
    return 0;  
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值