hdu 4930 Fighting the Landlords(模拟)

本文介绍了一种针对斗地主游戏的策略算法,详细解析了游戏中的各种牌型组合及对比规则,并通过实例展示了如何判断玩家是否能在当前轮次中获胜。

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

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): 1337 Accepted Submission(s): 492

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

分析
这是一道模拟好题呀,(相当考验的我的耐心)。
样例数据有些弱,要自己出数据才能测出一些bug

判断的顺序
1.能不能一次出完?
2.有没有王炸
3.比较炸弹
4.比较个子,对子,三带,四带

#include<iostream>
#include<map>
#include<set>
using namespace std;
map<char,int> func;
int main(){
    //freopen("in.txt","r",stdin);
    int n;
    cin>>n;
    for(int i=3;i<=9;i++)
        func[i+'0']=i;
    func['T']=10;
    func['J']=11;
    func['Q']=12;
    func['K']=13;
    func['A']=14;
    func['2']=15;
    func['X']=16;
    func['Y']=17;
    while(n--){
        string a,b;
        map<char,int> ma,mb;
        cin>>a>>b;
        for(int i=0;i<a.size();i++){
            ma[a[i]]++;
        }

        int wa1=0,wa2=0,wb1=0,wb2=0;

        map<char,int>::iterator it=ma.begin();
        set<char> na1,na2,na3,na4;
        for(;it!=ma.end();it++){
            if(ma['Y']==1)
                wa1=1;
            if(ma['X']==1)
                wa2=1;

            if(it->second==4)
                na4.insert(it->first);
            if(it->second==3)
                na3.insert(it->first);
            if(it->second==2)
                na2.insert(it->first);
            if(it->second==1)
                na1.insert(it->first);
        }

        for(int i=0;i<b.size();i++){
            mb[b[i]]++;
        }
        set<char> nb1,nb2,nb3,nb4;
        it=mb.begin();
        for(;it!=mb.end();it++){
            if(mb['Y']==1)
                wb1=1;
            if(mb['X']==1)
                wb2=1;

            if(it->second==4)
                nb4.insert(it->first);
            if(it->second==3)
                nb3.insert(it->first);
            if(it->second==2)
                nb2.insert(it->first);
            if(it->second==1)
                nb1.insert(it->first);
        }
        set<char>::iterator is;     

        //if 1 time go ,must win
        int now=0;
        if(a.size()<=6){
            if(a.size()==6){
                if(na4.size()==1){
                    cout<<"Yes"<<endl;
                    now=1;
                }
            }
            if(a.size()==5){
                if(na3.size()==1&&na2.size()==1){
                    cout<<"Yes"<<endl;
                    now=1; 
                }
            }
            if(a.size()==4 ){
                if(na4.size()==1 || (na3.size()==1&&na1.size()==1) ){
                    cout<<"Yes"<<endl;
                    now=1;
                }
            }
            if(a.size()==3){
                if(na3.size()==1){
                    cout<<"Yes"<<endl;
                    now=1;
                }
            }
            if(a.size()==2){
                if(na2.size()==1){
                    cout<<"Yes"<<endl;
                    now=1;
                }
            }
            if(a.size()==1){
                cout<<"Yes"<<endl;
                now=1;
            }
        }
        if(now)
            continue;

        //if double joker ,must win
        if(wa1&&wa2){
            //cout<<"double Joker"<<endl;
            cout<<"Yes"<<endl;
            now=1;
        }
        else if(wb1&&wb2){
            cout<<"No"<<endl;
            now=1;
        }
        if(now)
            continue;

        // 4-num boom
        int numa=0,numb=0;
        for(is=na4.begin();is!=na4.end();is++){
            if(is!=na4.end()&&func[*is]>numa){
                numa=func[*is];
            }
        }
        for(is=nb4.begin();is!=nb4.end();is++){
            if(is!=nb4.end()&&func[*is]>numb){
                numb=func[*is];
            }
        }
        if(numa>numb&&numa){
            //cout<<"boom"<<endl;           
            cout<<"Yes"<<endl;
            now=1;
        }
        else if(numa<numb){
            cout<<"No"<<endl;
            now=1;
        }
        if(now)
            continue;

        // No boom, compare Solo
        numa=0,numb=0;
        for(int i=0;i<a.size();i++){
            if(func[a[i]]>numa)
                numa=func[a[i]];
        }
        for(int i=0;i<b.size();i++){
            if(func[b[i]]>numb)
                numb=func[b[i]];
        }   

        if(numa>=numb&&numa){
            //cout<<"Solo"<<endl;
            cout<<"Yes"<<endl;
            now=1;
        }
        if(now)
            continue;

        // compare Pair
        numa=0,numb=0;
        for(is=na2.begin();is!=na2.end();is++){
            if(is!=na2.end()&&func[*is]>numa){
                numa=func[*is];
            }
        }   
        for(is=nb2.begin();is!=nb2.end();is++){
            if(is!=nb2.end()&&func[*is]>numb){
                numb=func[*is];
            }
        }
        if(numa>=numb&&numa){
            //cout<<"Pair"<<endl;
            cout<<"Yes"<<endl;
            now=1;
        }
        if(now)
            continue;
        // Compare Trio  
        //case 1 777+x>444+y
        numa=0,numb=0;
        for(is=na3.begin();is!=na3.end();is++){
            if(is!=na3.end()&&func[*is]>numa){
                numa=func[*is];
            }
        }   
        for(is=nb3.begin();is!=nb3.end();is++){
            if(is!=nb3.end()&&func[*is]>numb){
                numb=func[*is];
            }
        }
        if(numa>=numb&&numa){
            //cout<<"Trio"<<endl;
            //cout<<"numa="<<numa<<endl;
            //cout<<"numb="<<numb<<endl;
            cout<<"Yes"<<endl;
            now=1;
        }
        else if(numa < numb &&numa ){   
            if(na2.size()&& na2.size()==0){
                cout<<"Yes"<<endl;
                now=1;
            }
            if(a.size()>3 &&b.size()==3){
                cout<<"Yes"<<endl;
                now=1;
            }
        }
        if(now)
            continue;
        cout<<"No"<<endl;
    }
} 
内容概要:本文档提供了关于“微型车间生产线的设计与生产数据采集试验研究”的毕业设计复现代码,涵盖从论文结构生成、机械结构设计、PLC控制系统设计、生产数据采集与分析系统、有限元分析、进度管理、文献管理和论文排版系统的完整实现。通过Python代码和API调用,详细展示了各个模块的功能实现和相互协作。例如,利用SolidWorks API设计机械结构,通过PLC控制系统模拟生产流程,使用数据分析工具进行生产数据的采集和异常检测,以及利用进度管理系统规划项目时间表。 适合人群:具有机械工程、自动化控制或计算机编程基础的学生或研究人员,尤其是从事智能制造领域相关工作的人员。 使用场景及目标:①帮助学生或研究人员快速搭建和理解微型车间生产线的设计与实现;②提供完整的代码框架,便于修改和扩展以适应不同的应用场景;③作为教学或科研项目的参考资料,用于学习和研究智能制造技术。 阅读建议:此资源不仅包含详细的代码实现,还涉及多个学科领域的知识,如机械设计、电气控制、数据分析等。因此,在学习过程中,建议读者结合实际操作,逐步理解每个模块的功能和原理,并尝试调整参数以观察不同设置下的系统表现。同时,可以参考提供的文献资料,深入研究相关理论和技术背景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值