模拟斗地主——HDU 4930

对应HDU题目:点击打开链接

Fighting the Landlords

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 986    Accepted Submission(s): 360

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, theKicker’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 youin 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, andeach 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

题意:就是一人一手牌;问A能否一次出完或者A出牌后B接不了,苦逼刚开始以为A要把整手牌出完(⊙_⊙)。。。

组牌:单张,对子,三条,3夹1,   3夹2(要夹一个对子。。。), 4条(即炸弹), 4夹2(夹的可以是不同的牌),XY(王炸)

思路:先判断A有没有王炸,如有,直接Yes,如果A没有一次出完而B有王炸,直接No,接着判断炸弹如果A有炸弹且比B大,Yes,否则如果B有炸弹,No;之后判断其他(顺序随便)。。。

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
const int MAXN=1000+10;
using namespace std;

struct Card//保存两人手里各种组牌(如3夹2,4夹2等等)的最大值
{
    Card(){one=0;two=0;three=0;three_1=0;three_2=0;four=0;four_2=0;xy=0;len=0;}
    int one,two,three,three_1,three_2,four,four_2,xy,len;
};

void cal(char *s, int *num)//计算各种牌有多少个,如num[14]表示A有num[14]张
{
    for(int i=0; i<strlen(s); i++){
        if(s[i]=='T') num[10]++;
        if(s[i]=='J') num[11]++;
        if(s[i]=='Q') num[12]++;
        if(s[i]=='K') num[13]++;
        if(s[i]=='A') num[14]++;
        if(s[i]=='2') num[15]++;//注意这里。。。不要放到num[2]那里了
        if(s[i]=='X') num[16]++;
        if(s[i]=='Y') num[17]++;
        if('3'<=s[i] && s[i]<='9') num[s[i]-'0']++;
    }
}

void attack(Card &c, int *num)//计算c的各组牌的最大值
{
    if(num[16] && num[17]) c.xy=1;
    for(int i=3; i<=17; i++){
        if(num[i]) c.one=i;
        if(num[i]>=2) c.two=i;
        if(num[i]>=3) c.three=i;
        if(num[i]>=4) c.four=i;
        if(num[i]>=4 && c.len>=6) c.four_2=i;
        if(num[i]>=3 && c.len>=5){
            for(int j=1; j<=15; j++)
            if(i!=j && num[j]>=2) {c.three_2=i;break;}
        }
        if(num[i]>=3 && c.len>=4) c.three_1=i;
    }
}

bool first(char *s, Card c)//判断能否一次出完
{
    int len=strlen(s);
    if(c.xy && 2==len) return 1;
    if(c.four && 4==len) return 1;
    if(c.four_2 && 6==len) return 1;
    if(c.three_2 && 5==len) return 1;
    if(c.three_1 && 4==len) return 1;
    if(c.three && 3==len) return 1;
    if(c.two && 2==len) return 1;
    if(c.one && 1==len) return 1;
    return 0;
}

int main()
{
    //freopen("in.txt","r",stdin);
    char s1[20],s2[20];
    int T;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%s%s", s1,s2);
        Card c1,c2;
        c1.len=strlen(s1);
        c2.len=strlen(s2);
        int num1[20]={0},num2[20]={0};
        cal(s1,num1);
        cal(s2,num2);
        attack(c1,num1);
        attack(c2,num2);
        if(first(s1,c1)) {printf("Yes\n");continue;}//一次出完
        if(c1.xy) {printf("Yes\n");continue;}//有王炸
        if(c2.xy) {printf("No\n");continue;}//对方有王炸
        if(c1.four && c1.four >= c2.four) {printf("Yes\n");continue;}//有炸弹且比对方大
        else {if(c2.four) {printf("No\n");continue;}}//这里也错了不少次。。。
        if(c1.three_2 && c1.three_2 >= c2.three_2) {printf("Yes\n");continue;}//有3夹2且比对方大
        if(c1.one >= c2.one) {printf("Yes\n");continue;}//单张比对方大
        if(c1.two && c1.two >= c2.two) {printf("Yes\n");continue;}//有对子且比对方大
        if(c1.three && c1.three >= c2.three) {printf("Yes\n");continue;}//有3条且比对方大
        if(c1.three_1 && c1.three_1 >= c2.three_1) {printf("Yes\n");continue;}//有3夹1且比对方大
        printf("No\n");
    }
    return 0;
}
时间: 2024-10-11 11:36:24

模拟斗地主——HDU 4930的相关文章

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(模拟)

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

Hdu 4930 斗地主

模拟题,只是想纪念下,WA到死了…… 看到好多代码都好长,其实想说不用这么暴力. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algorithm> 7 #include <string> 8 #include <queue> 9

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(暴力枚举+模拟)

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 模拟

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

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> #inclu

HDU 4930 模拟

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