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 = ;
 11 vector<int> tot1[],tot2[];
 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==) return true;
 22     if(n1==) {
 23         if(tot1[].size()==) return true;
 24     }
 25    // printf("%d %d\n",cnt1[56],cnt1[55]);
 26     if(cnt1[]==&&cnt1[]==) return true;
 27     if(n1==) {
 28         if(tot1[].size()==) return true;
 29     }
 30     if(n1==) {
 31         if(tot1[].size()==&&tot1[].size()==) return true;
 32     }
 33     if(n1==) {
 34         if((tot1[].size()==&&tot1[].size()==)) return true;
 35     }
 36     if(n1==) {
 37         if((tot1[].size()==&&tot1[].size()==)||(tot1[].size()==&&tot1[].size()==))
 38         return true;
 39     }
 40     if(cnt2[]==&&cnt2[]==) return false;
 41 
 42     if(tot1[].size()!=) {
 43         int t=tot1[].size();
 44         int x=tot1[][t-];
 45         if(tot2[].size()==) {
 46             if(tot2[].size()==) return true;
 47             else if(tot2[].size()!=){
 48                 int m=tot2[].size();
 49                 int y=tot2[][m-];
 50                 if(x>y) return true;
 51             }
 52         }
 53     }
 54     if(tot1[].size()!=) {
 55         int t=tot1[].size();
 56         int x=tot1[][t-];
 57         if(tot2[].size()==) {
 58             if(tot2[].size()==) return true;
 59             else if(tot2[].size()!=){
 60                 int m=tot2[].size();
 61                 int y=tot2[][m-];
 62                 if(x>y) return true;
 63             }
 64         }
 65     }
 66     if(tot1[].size()!=) {
 67         int t=tot1[].size();
 68         int x=tot1[][t-];
 69         if(tot2[].size()==) {
 70             if(tot2[].size()==) return true;
 71             else if (tot2[].size()!=){
 72                 int m=tot2[].size();
 73                 int y=tot2[][m-];
 74                 if(x>y) return true;
 75             }
 76         }
 77     }
 78     if(tot1[].size()!=) {
 79         int t=tot1[].size();
 80         int x=tot1[][t-];
 81         if(tot2[].size()==) return true;
 82         else {
 83              int m=tot2[].size();
 84              int y=tot2[][m-];
 85              if(x>y) return true;
 86         }
 87     }
 88 
 89     return false;
 90 }
 91 void init() {
 92     for(int i=;i<=;i++) {
 93         tot1[i].clear();
 94         tot2[i].clear();
 95     }
 96 }
 97 int main() {
 98     int cas;
 99     scanf("%d",&cas);
     while(cas--) {
         init();
         scanf("%s %s",str1,str2);
         memset(cnt1,,sizeof(cnt1));
         memset(cnt2,,sizeof(cnt2));
         int n1=strlen(str1);
         int n2=strlen(str2);
         for(int i=;i<n1;i++) {
             if(str1[i]=='Y') a[i]=;
             else if(str1[i]=='X') a[i]=;
             else if(str1[i]=='') a[i]=;
             else if(str1[i]=='A') a[i]=;
             else if(str1[i]=='K') a[i]=;
             else if(str1[i]=='Q') a[i]=;
             else if(str1[i]=='J') a[i]=;
             else if(str1[i]=='T') a[i]=;
             else a[i]=str1[i]-'';
         }
         for(int i=;i<n2;i++) {
             if(str2[i]=='Y') b[i]=;
             else if(str2[i]=='X') b[i]=;
             else if(str2[i]=='') b[i]=;
             else if(str2[i]=='A') b[i]=;
             else if(str2[i]=='K') b[i]=;
             else if(str2[i]=='Q') b[i]=;
             else if(str2[i]=='J') b[i]=;
             else if(str2[i]=='T') b[i]=;
             else b[i]=str2[i]-'';
         }
         sort(a,a+n1,cmp);
         sort(b,b+n2,cmp);
         for(int i=;i<n1;i++) {
             cnt1[a[i]]++;
         }
         for(int i=;i<n2;i++) {
             cnt2[b[i]]++;
         }
         for(int i=;i<=;i++) {
             if(cnt1[i]) {
                 int num=cnt1[i];
                 while(num) {
                     tot1[num].push_back(i);
                     num--;
                 }
             }
         }
         for(int i=;i<=;i++) {
             if(cnt2[i]) {
                 int num=cnt2[i];
                 while(num) {
                     tot2[num].push_back(i);
                     num--;
                 }
             }
         }
 
         for(int i=;i<=;i++) {
             sort(tot1[i].begin(),tot1[i].end());
             sort(tot2[i].begin(),tot2[i].end());
         }
         int ans=check(n1,n2);
         if(ans) printf("Yes\n");
         else printf("No\n");
 
     }
     return ;

166 }

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

  1. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  2. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  3. HDU 4023 (博弈 贪心 模拟) Game

    如果硬要说这算是博弈题目的话,那这个博弈是不公平博弈(partizan games),因为双方面对同一个局面做出来的决策是不一样的. 我们平时做的博弈都是公平博弈(impartial games),所 ...

  4. hdu 模拟 贪心 4550

    卡片游戏 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...

  5. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

  6. BZOJ1029: [JSOI2007]建筑抢修[模拟 贪心 优先队列]

    1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec  Memory Limit: 162 MBSubmit: 3785  Solved: 1747[Submit][Statu ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  8. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  9. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

随机推荐

  1. bzoj 1867: [Noi1999]钉子和小球【dp】

    设f[i][j]为掉到f[i][j]时的概率然后分情况随便转移一下就好 主要是要手写分数比较麻烦 #include<iostream> #include<cstdio> usi ...

  2. 解决phpmyadmin数据文件导入有限制的问题(只能导入2M以下)

    修改配置php.ini文件中三个参数: 1.upload_max_filesize 2.memory_limit 3.post_max_size 建议根据实际需要进行设置.

  3. C头文件中尖括号与双引号的区别及编译搜索顺序

    这两天被问到一个很有意思的问题:C头文件中尖括号与双引号有什么区别,以前只大约知道 <> 常用在系统库文件,"" 常用在自定义的借口文件中,那具体在gcc编译搜索过程中 ...

  4. 状压DP UVA 10817 Headmaster's Headache

    题目传送门 /* 题意:学校有在任的老师和应聘的老师,选择一些应聘老师,使得每门科目至少两个老师教,问最少花费多少 状压DP:一看到数据那么小,肯定是状压了.这个状态不好想,dp[s1][s2]表示s ...

  5. ViewPager(1)FragmentPagerAdapter

    FragmentPagerAdapter 适合只有少量的pager,所有pager同时全部存在,不会有被销毁的,page过多很容易内存溢出. 1,代码 1.1 ViewPagerMain.java i ...

  6. 全面学习ORACLE Scheduler特性(4)创建和管理Schedule

    三.使用Schedules 10g 中新推出的SCHEDULER可能确实会让很多初接触的朋友感觉晕头晕脑,相比之前的jobs,SCHEDULER中新增的概念太多.比如说jobs,仍然可以理解成之前版本 ...

  7. WCF wsdlexception(at/html):faultCode=INVALID_WSDL

    WCF 部署正常,通过浏览器查看服务也OK,但是通过SOAP UI创建客户端请求时就异常: wsdlexception(at/html):faultCode=INVALID_WSDL: Expecte ...

  8. Python之双色球选购和三级菜单问题

    1:双色球选购# 1 双色球(假设一共八个球,6个红球,球号1-32.2个蓝球,球号1-16)# 2 确保用户不能重复选择,不能超出范围# 3 用户输入有误时有相应的错误提示# 4 最后展示用户选择的 ...

  9. 创建对象——单例(Singleton)模式

      单例(Singleton)模式:   保证一个类在系统里只能有一个对象被实例化.   如:缓存池.数据库连接池.线程池.一些应用服务实例等.   难点:在多线程环境中,保证实例的唯一性.     ...

  10. Android开发——Snackbar使用详解

    http://blog.csdn.net/qq_19431333/article/details/52862348