HDU 4930 Fighting the Landlords --多Trick,较复杂模拟

题意:两个人A和B在打牌,只有题目给出的几种牌能出若A第一次出牌B压不住或者A一次就把牌出完了,那么A赢,输出Yes,否则若A牌没出完而且被B压住了,那么A输,输出No。

解法:知道规则,看清题目,搞清有哪些Trick,就可以直接模拟搞了。详见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define N 100102
#define M 22

char s1[24],s2[24];
int A[24],B[24];
int cnt1[20],cnt2[20];

int main()
{
    int n,i,j;
    int n1,n2;
    scanf("%d",&n);
    while(n--)
    {
        priority_queue<int> Single,Pair,Tri,Four,Nuke;
        priority_queue<int> Single2,Pair2,Tri2,Four2,Nuke2;
        scanf("%s",s1);
        scanf("%s",s2);
        n1 = strlen(s1);
        n2 = strlen(s2);
        for(i=0;i<n1;i++)
        {
            if(s1[i] >= ‘3‘ && s1[i] <= ‘9‘)
                A[i] = s1[i]-‘0‘;
            else if(s1[i] == ‘T‘)
                A[i] = 10;
            else if(s1[i] == ‘J‘)
                A[i] = 11;
            else if(s1[i] == ‘Q‘)
                A[i] = 12;
            else if(s1[i] == ‘K‘)
                A[i] = 13;
            else if(s1[i] == ‘A‘)
                A[i] = 14;
            else if(s1[i] == ‘2‘)
                A[i] = 15;
            else if(s1[i] == ‘X‘)
                A[i] = 16;
            else if(s1[i] == ‘Y‘)
                A[i] = 17;
        }
        for(i=0;i<n2;i++)
        {
            if(s2[i] >= ‘3‘ && s2[i] <= ‘9‘)
                B[i] = s2[i]-‘0‘;
            else if(s2[i] == ‘T‘)
                B[i] = 10;
            else if(s2[i] == ‘J‘)
                B[i] = 11;
            else if(s2[i] == ‘Q‘)
                B[i] = 12;
            else if(s2[i] == ‘K‘)
                B[i] = 13;
            else if(s2[i] == ‘A‘)
                B[i] = 14;
            else if(s2[i] == ‘2‘)
                B[i] = 15;
            else if(s2[i] == ‘X‘)
                B[i] = 16;
            else if(s2[i] == ‘Y‘)
                B[i] = 17;
        }
        sort(A,A+n1);
        sort(B,B+n2);
        memset(cnt1,0,sizeof(cnt1));
        memset(cnt2,0,sizeof(cnt2));
        for(i=0;i<n1;i++)   //计算A各种牌的个数
            cnt1[A[i]]++;
        for(i=0;i<n2;i++)   //计算B各种牌的个数
            cnt2[B[i]]++;
        for(i=3;i<=15;i++)
        {
            if(cnt1[i] == 4)         //出现四个,可以做四个出,可以做三个出,也可以做两个或一个出
                Four.push(i),Tri.push(i),Pair.push(i),Single.push(i);
            else if(cnt1[i] == 3)
                Tri.push(i),Pair.push(i),Single.push(i);
            else if(cnt1[i] == 2)
                Pair.push(i),Single.push(i);
            else if(cnt1[i] == 1)
                Single.push(i);
        }
        for(i=3;i<=15;i++)
        {
            if(cnt2[i] == 4)
                Four2.push(i),Tri2.push(i),Pair2.push(i),Single2.push(i);
            else if(cnt2[i] == 3)
                Tri2.push(i),Pair2.push(i),Single2.push(i);
            else if(cnt2[i] == 2)
                Pair2.push(i),Single2.push(i);
            else if(cnt2[i] == 1)
                Single2.push(i);
        }
        if(cnt1[16])    //有王,可以做单个出
            Nuke.push(16),Single.push(16);
        if(cnt1[17])
            Nuke.push(17),Single.push(17);
        if(cnt2[16])
            Nuke2.push(16),Single2.push(16);
        if(cnt2[17])
            Nuke2.push(17),Single2.push(17);
        if(Nuke.size() >= 2)    //双王,直接赢
        {
            puts("Yes");
            continue;
        }
        //-------------------------------下面判断能否一次出完
        if(n1 == 1)
        {
            puts("Yes");
            continue;
        }
        if(n1 == 2)
        {
            if(A[0] == A[1])
            {
                puts("Yes");
                continue;
            }
        }
        if(n1 == 3)
        {
            if(A[0] == A[1] && A[1] == A[2])
            {
                puts("Yes");
                continue;
            }
        }
        if(n1 == 4)
        {
            if(A[0] == A[1] && A[1] == A[2] && A[2] == A[3])
            {
                puts("Yes");
                continue;
            }
            if(A[0] != A[1] && A[1] == A[2] && A[2] == A[3])
            {
                puts("Yes");
                continue;
            }
            if(A[2] != A[3] && A[0] == A[1] && A[1] == A[2])
            {
                puts("Yes");
                continue;
            }
        }
        if(n1 == 5)
        {
            if(A[0] == A[1] && A[1] != A[2] && A[2] == A[3] && A[3] == A[4])
            {
                puts("Yes");
                continue;
            }
            if(A[3] == A[4] && A[2] != A[3] && A[0] == A[1] && A[1] == A[2])
            {
                puts("Yes");
                continue;
            }
        }
        if(n1 == 6)
        {
            int tag = 0;
            for(i=0;i<=2;i++)
            {
                if(A[i] == A[i+1] && A[i+1] == A[i+2] && A[i+2] == A[i+3])
                {
                    tag = 1;
                    break;
                }
            }
            if(tag)
            {
                puts("Yes");
                continue;
            }
        }
        //-----------------------------如果不能一次出完
        if(Nuke2.size() >= 2)                //对方有双王,必输
        {
            puts("No");
            continue;
        }
        if(!Nuke.empty() && Nuke2.empty())   //A有王,B没王
        {
            puts("Yes");
            continue;
        }
        if(!Nuke.empty() && !Nuke2.empty())  //都有王,看谁的大,如果A小,则不选择出王,继续
        {
            if(Nuke.top() > Nuke2.top())
            {
                puts("Yes");
                continue;
            }
        }
        if(Four.empty() && !Four2.empty())  //炸弹,如果不能一次出完又没炸弹,那么必会被炸,输
        {
            puts("No");
            continue;
        }
        if(!Four.empty() && Four2.empty())  //有炸弹出炸弹
        {
            puts("Yes");
            continue;
        }
        if(!Four.empty() && !Four2.empty())  //都有炸弹,A的如果小,因为不能一次出完,必输
        {
            if(Four.top() >= Four2.top())
            {
                puts("Yes");
                continue;
            }
            else
            {
                puts("No");
                continue;
            }
        }
        if(!Tri.empty() && Tri2.empty())    //三个的情况
        {
            puts("Yes");
            continue;
        }
        if(!Tri.empty() && !Tri2.empty())
        {
            if(Tri.top() >= Tri2.top())
            {
                puts("Yes");
                continue;
            }
            else if(n1 >= 4 && n2 <= 3)   //A有的带,B没得带
            {
                puts("Yes");
                continue;
            }
        }
        if(!Pair.empty() && Pair2.empty())     //对子
        {
            puts("Yes");
            continue;
        }
        if(!Pair.empty() && !Pair2.empty())
        {
            if(Pair.top() >= Pair2.top())
            {
                puts("Yes");
                continue;
            }
        }
        if(Single.empty() && !Single2.empty())   //单个牌
        {
            puts("No");
            continue;
        }
        if(!Single.empty() && Single2.empty())
        {
            puts("Yes");
            continue;
        }
        if(!Single.empty() && !Single2.empty())
        {
            if(Single.top() >= Single2.top())
            {
                puts("Yes");
                continue;
            }
        }
        puts("No");                                //如果以上都不满足,那么A输了,gg。
    }
    return 0;
}

HDU 4930 Fighting the Landlords --多Trick,较复杂模拟,布布扣,bubuko.com

时间: 2024-08-21 23:05:15

HDU 4930 Fighting the Landlords --多Trick,较复杂模拟的相关文章

hdu 4930 Fighting the Landlords (模拟)

Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 160    Accepted Submission(s): 52 Problem Description Fighting the Landlords is a card game which has been a heat for ye

HDU 4930 Fighting the Landlords(扯淡模拟题)

Fighting the Landlords 大意: 斗地主....   分别给出两把手牌,肯定都合法.每张牌大小顺序是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. 给你8种组合:1.

HDU 4930 Fighting the Landlords(暴力枚举+模拟)

HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型,如果先手能一步走完,或者一步让后手无法管上,就赢 思路:先枚举出两个人所有可能的牌型的最大值,然后再去判断即可 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct Player { int rank[15]; } p1, p2; int t, h

HDU 4930 Fighting the Landlords(模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 解题报告:斗地主,加了一个四张可以带两张不一样的牌,也可以带一对,判断打出一手牌之后,如果对手没有能够大过你的牌就输出Yes,或者如果你把手上的牌一次性打完也输出Yes,否则输出No,代码有280多行,表示光是敲代码就花了一个多小时,手速还是太慢. 1.首先判断手上的牌能不能一次打完 如果一次性打不完: 2.首先判断对方有没有一对王,有就输出No 3.判断对手有没有四张的牌,如果有,再判断自己

HDU 4930 Fighting the Landlords 模拟

_(:зゝ∠)_ 4带2居然不是炸弹,, #include <algorithm> #include <cctype> #include <cassert> #include <cstdio> #include <cstring> #include <climits> #include <vector> #include<iostream> using namespace std; #define N 18 #

2014多校第六场 1010 || HDU 4930 Fighting the Landlords (模拟)

题目链接 题意 : 玩斗地主,出一把,只要你这一把对方要不了或者你出这一把之后手里没牌了就算你赢. 思路 : 一开始看了第一段以为要出很多次,实际上只问了第一次你能不能赢或者能不能把牌出尽. 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 5 using namespace std ; 6 7 char str1[20],str2[20] ; 8 int hash1[20],hash2[2

hdu 4930 Fighting the Landlords

Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 480    Accepted Submission(s): 163 Problem Description Fighting the Landlords is a card game which has been a heat for y

HDU 4930 Fighting the Landlords (超级暴力+读懂题意)

题目链接:HDU 4930 Fighting the Landlords 斗地主!!.不会玩这游戏,真是苦逼.题意其他都还好,就是要注意只要第一个回合1号玩家能压制2号玩家就算赢了(突破点). 其他就分类暴力了,思路还是比较清晰的. 注意点: 1.对方炸弹,必输 2.一回合就出完牌,必胜 AC代码: #include<stdio.h> #include<string.h> int vis1[30],vis2[30]; int find(char s) { if(s=='T') re

2014多校联合六(HDU 4923 HDU 4925 HDU 4927 HDU 4930)

HDU 4923 Room and Moor 题意:给出A序列  求满足题目所写的B序列  使得方差最小 思路:可以想到最后的结果中  B序列的值一定是一段一段的  那么我们可以类似贪心去搞  对于一段序列我们可以求出什么样的b值使得方差最小  即序列中1的个数除以序列长度  又因为B是单调的  可以用一个单调栈去模拟  复杂度远远小于n^2  不要被吓怕- 代码: #include<cstdio> #include<cstring> #include<algorithm&g