HDU 4930 : Fighting the Landlords(模拟)

J - Fighting the Landlords
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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. 
 

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


一个很简单的斗地主模拟题,一把定输赢。可以按照以下的顺序去判断输赢

1、判断己方是否可以一把打完手里的牌,如果可以就直接输出Yes

2、判断是否有一方有王炸,如果我方有,输出“Yes”,对方有就"No"

3、判断我方一次出牌数是否比对方多,如果是输出"Yes"

4、判断双方 a、单张的大小 b、两张的大小 c、三张的大小  (注意单张和对的时候,相同大小我方也赢)

5、如果以上判断后我方还不能赢就输出“No” 


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
using namespace std;

struct node 
{
    char pai[100];
    int x;
};
char me[20];
char you[20];
node mm[10];
node yy[10];

char s[16]={ 'Y','X','2','A','K','Q','J','T','9','8','7','6','5','4','3' };

int cmp(char a,char b)  //对手牌的大小进行排序
{
    int x, y;
    for(int i=0;i<16;i++)
    {
        if(s[i]==a)
            x=i;
        if(s[i]==b)
            y=i;
    }
    return x<y;
}


int main()
{
    int i,j,m,n,k,t;
    cin>>t;

    map<char,int> mp;
    map<char,int> mpp;
    while(t--)
    {
        cin>>me;
        cin>>you;
        mp.clear();
        mpp.clear();
        for(i=0;i<10;i++)
        {
            memset(mm[i].pai,0,sizeof(mm[i].pai));
            mm[i].x=0;
            memset(yy[i].pai,0,sizeof(yy[i].pai));
            yy[i].x=0;
        }

        for(i=0;i<strlen(me);i++)
        {
            mp[me[i]]++;
        }
        map<char,int> ::iterator it;
        for(it=mp.begin();it!=mp.end();it++)  
        {
            if(it->second==1)
            {
                mm[1].pai[mm[1].x]=it->first;
                mm[1].x++;
            }
            if(it->second==2)
            {
                mm[2].pai[mm[2].x]=it->first;
                mm[2].x++;
                mm[1].pai[mm[1].x]=it->first;
                mm[1].x++;
            }
            if(it->second==3)
            {
                mm[3].pai[mm[3].x]=it->first;
                mm[3].x++;
                mm[2].pai[mm[2].x]=it->first;
                mm[2].x++;
                mm[1].pai[mm[1].x]=it->first;
                mm[1].x++;
            }
            if(it->second==4)
            {
                mm[4].pai[mm[4].x]=it->first;
                mm[4].x++;
                mm[3].pai[mm[3].x]=it->first;
                mm[3].x++;
                mm[2].pai[mm[2].x]=it->first;
                mm[2].x++;
                mm[1].pai[mm[1].x]=it->first;
                mm[1].x++;
            }
        }

        for(i=0;i<strlen(you);i++)
        {
            mpp[you[i]]++;
        }

        for(it=mpp.begin();it!=mpp.end();it++)
        {
            if(it->second==1)
            {
                yy[1].pai[yy[1].x]=it->first;
                yy[1].x++;
            }
            if(it->second==2)
            {
                yy[2].pai[yy[2].x]=it->first;
                yy[2].x++;
                yy[1].pai[yy[1].x]=it->first;
                yy[1].x++;
            }
            if(it->second==3)
            {
                yy[3].pai[yy[3].x]=it->first;
                yy[3].x++;
                yy[2].pai[yy[2].x]=it->first;
                yy[2].x++;
                yy[1].pai[yy[1].x]=it->first;
                yy[1].x++;
            }
            if(it->second==4)
            {
                yy[4].pai[yy[4].x]=it->first;
                yy[4].x++;
                yy[3].pai[yy[3].x]=it->first;
                yy[3].x++;
                yy[2].pai[yy[2].x]=it->first;
                yy[2].x++;
                yy[1].pai[yy[1].x]=it->first;
                yy[1].x++;
            }
        }
        
        sort(mm[1].pai,mm[1].pai+mm[1].x,cmp);
        sort(mm[2].pai,mm[2].pai+mm[2].x,cmp);
        sort(mm[3].pai,mm[3].pai+mm[3].x,cmp);
        sort(mm[4].pai,mm[4].pai+mm[4].x,cmp);

        sort(yy[1].pai,yy[1].pai+yy[1].x,cmp);
        sort(yy[2].pai,yy[2].pai+yy[2].x,cmp);
        sort(yy[3].pai,yy[3].pai+yy[3].x,cmp);
        sort(yy[4].pai,yy[4].pai+yy[4].x,cmp);
	
		//判断能否一次出完牌
        int mylen=strlen(me);   
        if(mylen==1)
        {
            cout<<"Yes"<<endl;
            continue;
        }
        if(mylen==2)
        {
            if(mm[2].x!=0)
            {
                cout<<"Yes"<<endl;
                continue;
            }
        }
        if(mylen==3)
        {
            if(mm[3].x!=0)
            {
                cout<<"Yes"<<endl;
                continue;
            }
        }
        if(mylen==4)
        {
            if(mm[4].x!=0 )
            {
                cout<<"Yes"<<endl;
                continue;
            }
            if( mm[3].x!=0 && mm[1].x>=2)
            {
                cout<<"Yes"<<endl;
                continue;
            }
        }
        if(mylen==5)
        {
            if(mm[3].x!=0 && mm[2].x>=2)
            {
                cout<<"Yes"<<endl;
                continue;
            }
        }
        if(mylen==6)
        {
            if( (mm[4].x!=0 && mm[2].x>=2) || (mm[4].x!=0 && mm[1].x>=3) )
            {
                cout<<"Yes"<<endl;
                continue;
            }
        }
        
		//判断是否一方有王炸
        if(mm[1].pai[0]=='Y' && mm[1].pai[1]=='X')
        {
            cout<<"Yes"<<endl;
            continue;
        }

        if( yy[1].pai[0]=='Y' && yy[1].pai[1]=='X')
        {
            cout<<"No"<<endl;
            continue;
        }

        if( mm[4].x!=0 && yy[4].x==0)
        {
            cout<<"Yes"<<endl;
            continue;
        }
        if( mm[4].x==0 && yy[4].x!=0)
        {
            cout<<"No"<<endl;
            continue;
        }
        if( mm[4].x!=0 && yy[4].x!=0)
        {
            if(cmp (mm[4].pai[0],yy[4].pai[0])>0)
            {
                cout<<"Yes"<<endl;
                continue;
            }
            else
            {
                cout<<"No"<<endl;
                continue;
            }
        }


		//判断我方一次出牌数是否大于下家
        int zhangshu=0;
        int zhangshu2=0;

        if(mm[2].x!=0)
        {
            zhangshu=2;
        }
        if(mm[3].x!=0)
        {
            zhangshu=3;
        }
        if(mm[4].x!=0 )
        {
            zhangshu=4;
        }
        if(mm[3].x!=0 && mm[1].x>=2)
        {
            zhangshu=4;
        }
        if(mm[3].x!=0 && mm[2].x>=2)
        {
            zhangshu=5;
        }
        if( (mm[4].x!=0 && mm[2].x>=2) || (mm[4].x!=0 && mm[1].x>=3))
        {
            zhangshu=6;
        }
        

        if(yy[2].x!=0)
        {
            zhangshu2=2;
        }
        if(yy[3].x!=0)
        {
            zhangshu2=3;
        }
        if(yy[4].x!=0 )
        {
            zhangshu2=4;
        }
        if(yy[3].x!=0 && yy[1].x>=2)
        {
            zhangshu2=4;
        }
        if( yy[3].x!=0 && yy[2].x>=2) 
        {
            zhangshu2=5;
        }
        if( (yy[4].x!=0 && yy[2].x>=2) || (yy[4].x!=0 && yy[1].x>=3))
        {
            zhangshu2=6;
        }

        if(zhangshu > zhangshu2) 
        {
            cout<<"Yes"<<endl;
            continue;
        }


        //判断双方出单张,一对,三张
        if(mm[1].pai[0]==yy[1].pai[0])
        {
            cout<<"Yes"<<endl;
            continue;
        }
        if( cmp(mm[1].pai[0],yy[1].pai[0] )>0 )
        {
            cout<<"Yes"<<endl;
            continue;
        }
  
        if(mm[2].pai[0]==yy[2].pai[0] && mm[2].x!=0 && yy[2].x!=0)
        {
            cout<<"Yes"<<endl;
            continue;
        }
        if( cmp(mm[2].pai[0],yy[2].pai[0])>0 )
        {
            cout<<"Yes"<<endl;
            continue;    
        }

        if( cmp(mm[3].pai[0],yy[3].pai[0] )>0 )
        {
            cout<<"Yes"<<endl;
            continue;
        }

        cout<<"No"<<endl;
    }
     return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值