HDU 4903 (模拟+贪心)

Fighting the Landlords

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

题意:斗地主游戏规则,但是只有两个人玩这个游戏,当第一个人出一次牌第二个人无法出就算赢。

sL :很水的模拟了。直接存下单张的。对的。3个的。4个的。 开4个数组就可以了。

1 // by caonima
  2 // hehe
  3 #include <cstdio>
  4 #include <cstring>
  5 #include <algorithm>
  6 #include <vector>
  7 #include <queue>
  8 #include <set>
  9 using namespace std;
 10 const int MAX = 100;
 11 vector<int> tot1[5],tot2[5];
 12 char str1[MAX];
 13 char str2[MAX];
 14 int a[MAX],b[MAX];
 15 int cnt1[MAX],cnt2[MAX];
 16 int cmp(int a,int b) {
 17     return a>b;
 18 }
 19 
 20 int check(int n1,int n2) {
 21     if(n1==1) return true;
 22     if(n1==2) {
 23         if(tot1[2].size()==1) return true;
 24     }
 25    // printf("%d %d\n",cnt1[56],cnt1[55]);
 26     if(cnt1[56]==1&&cnt1[55]==1) return true;
 27     if(n1==3) {
 28         if(tot1[3].size()==1) return true;
 29     }
 30     if(n1==4) {
 31         if(tot1[3].size()==1&&tot1[1].size()==2) return true;
 32     }
 33     if(n1==5) {
 34         if((tot1[3].size()==1&&tot1[2].size()==2)) return true;
 35     }
 36     if(n1==6) {
 37         if((tot1[4].size()==1&&tot1[2].size()==2)||(tot1[4].size()==1&&tot1[1].size()==3))
 38         return true;
 39     }
 40     if(cnt2[55]==1&&cnt2[56]==1) return false;
 41 
 42     if(tot1[1].size()!=0) {
 43         int t=tot1[1].size();
 44         int x=tot1[1][t-1];
 45         if(tot2[4].size()==0) {
 46             if(tot2[1].size()==0) return true;
 47             else if(tot2[1].size()!=0){
 48                 int m=tot2[1].size();
 49                 int y=tot2[1][m-1];
 50                 if(x>y) return true;
 51             }
 52         }
 53     }
 54     if(tot1[2].size()!=0) {
 55         int t=tot1[2].size();
 56         int x=tot1[2][t-1];
 57         if(tot2[4].size()==0) {
 58             if(tot2[2].size()==0) return true;
 59             else if(tot2[2].size()!=0){
 60                 int m=tot2[2].size();
 61                 int y=tot2[2][m-1];
 62                 if(x>y) return true;
 63             }
 64         }
 65     }
 66     if(tot1[3].size()!=0) {
 67         int t=tot1[3].size();
 68         int x=tot1[3][t-1];
 69         if(tot2[4].size()==0) {
 70             if(tot2[3].size()==0) return true;
 71             else if (tot2[3].size()!=0){
 72                 int m=tot2[3].size();
 73                 int y=tot2[3][m-1];
 74                 if(x>y) return true;
 75             }
 76         }
 77     }
 78     if(tot1[4].size()!=0) {
 79         int t=tot1[4].size();
 80         int x=tot1[4][t-1];
 81         if(tot2[4].size()==0) return true;
 82         else {
 83              int m=tot2[4].size();
 84              int y=tot2[4][m-1];
 85              if(x>y) return true;
 86         }
 87     }
 88 
 89     return false;
 90 }
 91 void init() {
 92     for(int i=0;i<=4;i++) {
 93         tot1[i].clear();
 94         tot2[i].clear();
 95     }
 96 }
 97 int main() {
 98     int cas;
 99     scanf("%d",&cas);
100     while(cas--) {
101         init();
102         scanf("%s %s",str1,str2);
103         memset(cnt1,0,sizeof(cnt1));
104         memset(cnt2,0,sizeof(cnt2));
105         int n1=strlen(str1);
106         int n2=strlen(str2);
107         for(int i=0;i<n1;i++) {
108             if(str1[i]==‘Y‘) a[i]=56;
109             else if(str1[i]==‘X‘) a[i]=55;
110             else if(str1[i]==‘2‘) a[i]=54;
111             else if(str1[i]==‘A‘) a[i]=53;
112             else if(str1[i]==‘K‘) a[i]=52;
113             else if(str1[i]==‘Q‘) a[i]=51;
114             else if(str1[i]==‘J‘) a[i]=50;
115             else if(str1[i]==‘T‘) a[i]=49;
116             else a[i]=str1[i]-‘0‘;
117         }
118         for(int i=0;i<n2;i++) {
119             if(str2[i]==‘Y‘) b[i]=56;
120             else if(str2[i]==‘X‘) b[i]=55;
121             else if(str2[i]==‘2‘) b[i]=54;
122             else if(str2[i]==‘A‘) b[i]=53;
123             else if(str2[i]==‘K‘) b[i]=52;
124             else if(str2[i]==‘Q‘) b[i]=51;
125             else if(str2[i]==‘J‘) b[i]=50;
126             else if(str2[i]==‘T‘) b[i]=49;
127             else b[i]=str2[i]-‘0‘;
128         }
129         sort(a,a+n1,cmp);
130         sort(b,b+n2,cmp);
131         for(int i=0;i<n1;i++) {
132             cnt1[a[i]]++;
133         }
134         for(int i=0;i<n2;i++) {
135             cnt2[b[i]]++;
136         }
137         for(int i=0;i<=57;i++) {
138             if(cnt1[i]) {
139                 int num=cnt1[i];
140                 while(num) {
141                     tot1[num].push_back(i);
142                     num--;
143                 }
144             }
145         }
146         for(int i=0;i<=57;i++) {
147             if(cnt2[i]) {
148                 int num=cnt2[i];
149                 while(num) {
150                     tot2[num].push_back(i);
151                     num--;
152                 }
153             }
154         }
155 
156         for(int i=0;i<=4;i++) {
157             sort(tot1[i].begin(),tot1[i].end());
158             sort(tot2[i].begin(),tot2[i].end());
159         }
160         int ans=check(n1,n2);
161         if(ans) printf("Yes\n");
162         else printf("No\n");
163 
164     }
165     return 0;

166 }

HDU 4903 (模拟+贪心)

时间: 2024-10-13 22:03:56

HDU 4903 (模拟+贪心)的相关文章

HDU 4811 Ball(贪心)

2014-05-15 22:02 by Jeff Li 前言 系列文章:[传送门] 马上快要期末考试了,为了学点什么.就准备这系列的博客,记录复习的成果. 正文-计数  概率 概率论研究随机事件.它源于赌徒的研究.即使是今天,概率论也常用于赌博.随机事件的结果是否只凭运气呢?高明的赌徒发现了赌博中的规律.尽管我无法预知事件的具体结果,但我可以了解每种结果出现的可能性.这是概率论的核心. "概率"到底是什么?这在数学上还有争议."频率派"认为概率是重复尝试多次,某种结

hdu 4869 Task(贪心)

题目链接:hdu 4869 Task 题目大意:有n台机器,m个任务,每个机器和任务都有有xi和yi,要求机器的xi,yi均大于等于任务的xi和yi才能执行任务.每台机器一天只能执行一个任务.要求完成的任务数尽量多,并且说金额尽量大.完成每个任务的金额为xi?500+yi?2 解题思路:贪心,mach[i][j]表示等级为i,时间为j的机器数量,task[i][j]表示等级为i,时间为j的机器数量.每次优先减少i,因为对应等级减少100,对应的金额代价也不会减少超过500(即时间减少1). 每次

HDU 4864 Task(贪心)

HDU 4864 Task 题目链接 题意:有一些机器和一些任务,都有时间和等级,机器能做任务的条件为时间等级都大于等于任务,并且一个任务只能被一个机器做,现在求最大能完成任务,并且保证金钱尽量多 思路:贪心,对于每个任务,时间大的优先去匹配,时间相同的,等级大的优先去匹配,因为时间占得多,时间多1就多500,而等级最多才差200.然后匹配的时候,尽量使用等级小的去匹配,而时间只要大于它的都可以用,因为是按时间优先,所以如果该时间能匹配大的,其他肯定也能匹配,那么肯定优先匹配大的,所以只要在等级

HDU 4912 LCA+贪心

Paths on the tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 531    Accepted Submission(s): 182 Problem Description bobo has a tree, whose vertices are conveniently labeled by 1,2,…,n. Th

HDU 1661 Assigments 贪心法题解

Problem Description In a factory, there are N workers to finish two types of tasks (A and B). Each type has N tasks. Each task of type A needs xi time to finish, and each task of type B needs yj time to finish, now, you, as the boss of the factory, n

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

2014多校第一场D题 || HDU 4864 Task (贪心)

题目链接 题意 : 用N台机器,M个任务,每台机器都有一个最大工作时间和等级,每个任务有一个需要工作时间和一个等级.如果机器完成一个任务要求是:机器的工作时间要大于等于任务的时间,机器的等级要大于等于任务的等级.一台机器只能完成一个任务,一个任务只能被一台机器完成.每个机器完成一个任务公司能够获得500*xi+2*yi (此处xy都是指被完成的任务的).输出所有机器能完成的最多任务数,和最大盈利. 思路 :贪心,自己做的时候想了各种排序都不对,没有考虑到500*xi+2*yi 这个公式的重要性.

hdu 4898 LCP+贪心思维

题意:将一个字符串切成k块,使得字典序最大的那块最小. ORZ  WJMZBMR,几行题解读了一天才懂. 快速比较两个子串的大小可以利用LCP(最长公共前缀),比较公共前缀的下一个字符的大小就够了. 利用这种思想,首先我们可以预处理所有子串的LCP(后缀数组+记录 O(2nlog(2n))+O(n*n),dp(O(4*n*n))) 然后将这些子串利用LCP按照字典序排序,开始二分答案. 二分的答案就是这K个块字典序的上限.假设以i作为起点,由于字典序上限已知,所以我们可以立刻求出i点最远能选到哪

HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可以工作的最长时间和一个可以完成的任务的难度的最大值, 一台机器能完成一个任务的条件是这台机器的最长工作时间和能完成任务的难度值必须都大于等于这个任务,而且一台机器最多完成一个任务,假设一个任务的时间为t,难度值为x,那么完成这个任务可以赚到的钱 money = 500 * t + 2 * x; 现在