HDU 4930-Fighting the Landlords(模拟)

本文详细介绍了一种斗地主游戏中玩家如何通过合理的牌型组合和策略应用来战胜对手的方法。通过对不同牌型如Solo、Pair、Trio等的优先级设定及特殊牌型如Nuke、Bomb的应用规则说明,文章提供了具体的编程实现案例,帮助读者理解如何判断当前手牌是否能在一轮中取得优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.
 

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。

CODE:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
const int inf=0xfffffff;
using namespace std;

char a[20],b[20],num[2][20];
bool cmp(int a,int b)
{
  return a>b;
}
int pa[5],pb[5];
map<char,int>m;
int sa[10],sb[10];
int maxa[5],maxb[5];

int test(int *p)
{
    if(p[1]==1 && p[2]==0 && p[3]==1 && p[4]==0) return 1;
    if(p[1]==0 && p[2]==1 && p[3]==1 && p[4]==0) return 1;
    if(p[1]==0 && p[2]==1 && p[3]==0 && p[4]==1) return 1;
    if(p[1]==2 && p[2]==0 && p[3]==0 && p[4]==1) return 1;
    if(p[1]==1 && p[2]==0 && p[3]==0 && p[4]==0) return 1;
    if(p[1]==0 && p[2]==1 && p[3]==0 && p[4]==0) return 1;
    if(p[1]==0 && p[2]==0 && p[3]==1 && p[4]==0) return 1;
    if(p[1]==0 && p[2]==0 && p[3]==0 && p[4]==1) return 1;
    return 0;
}
void get_max()
{
    int maxn;
    for(int i=1;i<=4;i++){
        maxn=0;
        for(int j=1;j<=15;j++){
            if(num[0][j]>=i && maxn<j) maxn=j;
        }
        maxa[i]=maxn;
    }
    for(int i=1;i<=4;i++){
        maxn=0;
        for(int j=1;j<=15;j++){
            if(num[1][j]>=i && maxn<j) maxn=j;
        }
        maxb[i]=maxn;
    }
}
void get_ans()
{
    sa[1]=maxa[1];
    sa[2]=maxa[2];
    sa[3]=maxa[3];
    sa[4]=maxa[4];
    if(pa[1]!=0 && maxa[3]!=0) sa[5]=maxa[3];
    if(pa[2]!=0 && maxa[3]!=0) sa[6]=maxa[3];
    if(pa[2]!=0 && maxa[4]!=0) sa[7]=maxa[4];
    if((pa[1]+pa[2]+pa[3])>=2 && maxa[4]!=0) sa[8]=maxa[4];
    if(num[0][14]!=0 && num[0][15]!=0) sa[9]=1;

    sb[1]=maxb[1];
    sb[2]=maxb[2];
    sb[3]=maxb[3];
    sb[4]=maxb[4];
    if(pb[1]!=0 && maxb[3]!=0) sb[5]=maxb[3];
    if(pb[2]!=0 && maxb[3]!=0) sb[6]=maxb[3];
    if(pb[2]!=0 && maxb[4]!=0) sb[7]=maxb[4];
    if(((pb[1]+pb[2]+pb[3])>=2||pb[4]>1) && maxb[4]!=0) sb[8]=maxb[4];
    if(num[1][14]!=0 && num[1][15]!=0) sb[9]=1;
}
void get_time(int *p,int ii)
{
    for(int i=0;i<=15;i++){
       if(num[ii][i]==1) p[1]++;
       if(num[ii][i]==2) p[2]++;
       if(num[ii][i]==3) p[3]++;
       if(num[ii][i]==4) p[4]++;
    }
}
int main()
{
   // freopen("1010.in","r",stdin);
    int t;
    scanf("%d",&t);
    m['3']=1;  m['4']=2;  m['5']=3;  m['6']=4;  m['7']=5;
    m['8']=6;  m['9']=7;  m['T']=8;  m['J']=9;  m['Q']=10;
    m['K']=11; m['A']=12; m['2']=13; m['X']=14; m['Y']=15;
    while(t--)
    {
        getchar();
        memset(a,0,sizeof(a)); memset(b,0,sizeof(b));
        memset(sa,0,sizeof(sa)); memset(sb,0,sizeof(sb));
        memset(num,0,sizeof(num));
        memset(pa,0,sizeof(pa)); memset(pb,0,sizeof(pb));
        memset(maxa,0,sizeof(maxa)); memset(maxb,0,sizeof(maxb));

        scanf("%s %s",a,b);

        for(int i=0;a[i]||b[i];i++)
        {
          if(a[i])num[0][m[a[i]]]++;
          if(b[i])num[1][m[b[i]]]++;
        }
        get_time(pa,0);
        get_time(pb,1);
        
        if(test(pa)) {
          printf("Yes\n");
          continue;
        }
        get_max();
        get_ans();

        int ok=1;
        for(int i=1;i<=9;i++){
          if(sa[i]!=0 && sa[i]>=sb[i])
              ok=0;
        }
        if(sa[9]==1) ok=0;
        else if(sb[9]==1) ok=1;
        else if(pb[4]!=0 && maxa[4]<maxb[4]) ok=1;

        if(ok) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值