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

题目意思:
两个人设为A和B,A和B在打斗地主,上面一行是A手里的牌,下面一行是B手里的牌,若A第一次出牌B压不住或者A一次就把牌出完了,那么输出Yes,否则若A牌没出完而且被B压住了那么输出No。

思路:

把A、B手里有什么牌记录下来,然后先判断A第一次出牌能不能出完,然后看A出的牌是否B压不住。

代码:

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <algorithm>
  4 #include <iostream>
  5 using namespace std;
  6
  7 int a1[6], b1[6];     //a1即为A手里有什么牌即单、对、三个、炸弹、王炸 ,b1是对应a1最大的牌,下面a2\b2也是这样
  8 int a2[6], b2[6];
  9 char s1[25];
 10 char s2[25];
 11 int c1[25];
 12 int c2[25];
 13
 14 void change(int *c,int t){
 15     int a[6], b[6], i;
 16     memset(a,0,sizeof(a));
 17     memset(b,0,sizeof(b));
 18     for(i=1;i<=13;i++){
 19         if(c[i]){
 20             b[1]=max(b[1],i);
 21             if(c[i]==1){
 22                 a[1]++;
 23             }
 24             else if(c[i]==2){
 25                 a[2]++;
 26                 b[2]=max(b[2],i);
 27             }
 28             else if(c[i]==3){
 29                 a[3]++;
 30                 b[3]=max(b[3],i);
 31             }
 32             else if(c[i]==4){
 33                 a[4]++;
 34                 b[4]=max(b[4],i);
 35             }
 36         }
 37     }
 38     if(c[14]&&c[15]){
 39         b[1]=15;
 40         a[5]++;
 41     }
 42     else if(c[14]){
 43         b[1]=14;
 44     }
 45     else if(c[15]){
 46         b[1]=15;
 47     }
 48     if(t==1){
 49         for(i=1;i<=5;i++) {
 50             a1[i]=a[i];
 51             b1[i]=b[i];
 52         }
 53     }
 54     else{
 55         for(i=1;i<=5;i++) {
 56             a2[i]=a[i];
 57             b2[i]=b[i];
 58         }
 59     }
 60
 61 }
 62
 63 int pan(char c){
 64     if(c>=‘3‘&&c<=‘9‘) return c-‘2‘;
 65     switch(c){
 66         case ‘T‘:return 8;
 67         case ‘J‘:return 9;
 68         case ‘Q‘:return 10;
 69         case ‘K‘:return 11;
 70         case ‘A‘:return 12;
 71         case ‘2‘:return 13;
 72         case ‘X‘:return 14;
 73         case ‘Y‘:return 15;
 74     }
 75 }
 76
 77
 78 void input(){
 79     int i, j;
 80     memset(a1,0,sizeof(a1));
 81     memset(b1,0,sizeof(b1));
 82     memset(a2,0,sizeof(a1));
 83     memset(b2,0,sizeof(b2));
 84     memset(c1,0,sizeof(c1));
 85     memset(c2,0,sizeof(c2));
 86
 87     scanf("%s%s",s1,s2);
 88     for(i=0;i<strlen(s1);i++){
 89         j=pan(s1[i]);
 90         c1[j]++;             //把A手里的牌转换为数字,数字大小即为牌的大小
 91     }
 92     for(i=0;i<strlen(s2);i++){
 93         j=pan(s2[i]);
 94         c2[j]++;          //B手里牌转换为数字
 95     }
 96     change(c1,1);          //处理A手里有什么类型牌和该类型最大的牌
 97     change(c2,2);            //处理B手里有什么牌和该类型最大的牌
 98 }
 99
100 void output(){
101     int i, j;
102     int flag1, flag2;
103     int n1=strlen(s1);
104     int n2=strlen(s2);
105     if((n1==1)||(n1==2&&a1[2])||(n1==3&&a1[3])||(n1==4&&(a1[4]||a1[3]))||(n1==5&&a1[2]&&a1[3])||(n1==6&&a1[2]&&a1[4])){
106         printf("Yes\n");//一次出完
107     }
108     else if(a1[5]){
109         printf("Yes\n"); //A手里有王炸
110     }
111     else if(a2[5]){
112         printf("No\n");   //B手里有王炸
113     }
114     else if(b1[4]>b2[4]){
115         printf("Yes\n");   //A手里的炸弹比B手里的炸弹大
116     }
117     else if(b1[4]<b2[4]){  //反之
118         printf("No\n");
119     }
120     else if(b1[1]>b2[1]){  //出单,且单比B的大
121         printf("Yes\n");
122     }
123     else if(b1[2]>b2[2]){  //出对,且对比B的大
124         printf("Yes\n");
125     }
126     else if(b1[3]&&(b1[3]>b2[3]||(b1[1]&&!b2[1])||(b1[2]&&!b2[2]))){  //出3张时,可以带1张也可以带2张也可以不带,依次判断
127         printf("Yes\n");
128     }
129     else {
130         printf("No\n");
131     }
132 }
133
134 main()
135 {
136     int t, i, j, k;
137     cin>>t;
138     while(t--){
139         input();
140         output();
141
142     }
143 }

HDU 4930 模拟,布布扣,bubuko.com

时间: 2024-12-25 04:16:30

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

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 #

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

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

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

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