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

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

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <queue>
  9. using namespace std;
  10. #define N 100102
  11. #define M 22
  12.  
  13. char s1[],s2[];
  14. int A[],B[];
  15. int cnt1[],cnt2[];
  16.  
  17. int main()
  18. {
  19. int n,i,j;
  20. int n1,n2;
  21. scanf("%d",&n);
  22. while(n--)
  23. {
  24. priority_queue<int> Single,Pair,Tri,Four,Nuke;
  25. priority_queue<int> Single2,Pair2,Tri2,Four2,Nuke2;
  26. scanf("%s",s1);
  27. scanf("%s",s2);
  28. n1 = strlen(s1);
  29. n2 = strlen(s2);
  30. for(i=;i<n1;i++)
  31. {
  32. if(s1[i] >= '' && s1[i] <= '')
  33. A[i] = s1[i]-'';
  34. else if(s1[i] == 'T')
  35. A[i] = ;
  36. else if(s1[i] == 'J')
  37. A[i] = ;
  38. else if(s1[i] == 'Q')
  39. A[i] = ;
  40. else if(s1[i] == 'K')
  41. A[i] = ;
  42. else if(s1[i] == 'A')
  43. A[i] = ;
  44. else if(s1[i] == '')
  45. A[i] = ;
  46. else if(s1[i] == 'X')
  47. A[i] = ;
  48. else if(s1[i] == 'Y')
  49. A[i] = ;
  50. }
  51. for(i=;i<n2;i++)
  52. {
  53. if(s2[i] >= '' && s2[i] <= '')
  54. B[i] = s2[i]-'';
  55. else if(s2[i] == 'T')
  56. B[i] = ;
  57. else if(s2[i] == 'J')
  58. B[i] = ;
  59. else if(s2[i] == 'Q')
  60. B[i] = ;
  61. else if(s2[i] == 'K')
  62. B[i] = ;
  63. else if(s2[i] == 'A')
  64. B[i] = ;
  65. else if(s2[i] == '')
  66. B[i] = ;
  67. else if(s2[i] == 'X')
  68. B[i] = ;
  69. else if(s2[i] == 'Y')
  70. B[i] = ;
  71. }
  72. sort(A,A+n1);
  73. sort(B,B+n2);
  74. memset(cnt1,,sizeof(cnt1));
  75. memset(cnt2,,sizeof(cnt2));
  76. for(i=;i<n1;i++) //计算A各种牌的个数
  77. cnt1[A[i]]++;
  78. for(i=;i<n2;i++) //计算B各种牌的个数
  79. cnt2[B[i]]++;
  80. for(i=;i<=;i++)
  81. {
  82. if(cnt1[i] == ) //出现四个,可以做四个出,可以做三个出,也可以做两个或一个出
  83. Four.push(i),Tri.push(i),Pair.push(i),Single.push(i);
  84. else if(cnt1[i] == )
  85. Tri.push(i),Pair.push(i),Single.push(i);
  86. else if(cnt1[i] == )
  87. Pair.push(i),Single.push(i);
  88. else if(cnt1[i] == )
  89. Single.push(i);
  90. }
  91. for(i=;i<=;i++)
  92. {
  93. if(cnt2[i] == )
  94. Four2.push(i),Tri2.push(i),Pair2.push(i),Single2.push(i);
  95. else if(cnt2[i] == )
  96. Tri2.push(i),Pair2.push(i),Single2.push(i);
  97. else if(cnt2[i] == )
  98. Pair2.push(i),Single2.push(i);
  99. else if(cnt2[i] == )
  100. Single2.push(i);
  101. }
  102. if(cnt1[]) //有王,可以做单个出
  103. Nuke.push(),Single.push();
  104. if(cnt1[])
  105. Nuke.push(),Single.push();
  106. if(cnt2[])
  107. Nuke2.push(),Single2.push();
  108. if(cnt2[])
  109. Nuke2.push(),Single2.push();
  110. if(Nuke.size() >= ) //双王,直接赢
  111. {
  112. puts("Yes");
  113. continue;
  114. }
  115. //-------------------------------下面判断能否一次出完
  116. if(n1 == )
  117. {
  118. puts("Yes");
  119. continue;
  120. }
  121. if(n1 == )
  122. {
  123. if(A[] == A[])
  124. {
  125. puts("Yes");
  126. continue;
  127. }
  128. }
  129. if(n1 == )
  130. {
  131. if(A[] == A[] && A[] == A[])
  132. {
  133. puts("Yes");
  134. continue;
  135. }
  136. }
  137. if(n1 == )
  138. {
  139. if(A[] == A[] && A[] == A[] && A[] == A[])
  140. {
  141. puts("Yes");
  142. continue;
  143. }
  144. if(A[] != A[] && A[] == A[] && A[] == A[])
  145. {
  146. puts("Yes");
  147. continue;
  148. }
  149. if(A[] != A[] && A[] == A[] && A[] == A[])
  150. {
  151. puts("Yes");
  152. continue;
  153. }
  154. }
  155. if(n1 == )
  156. {
  157. if(A[] == A[] && A[] != A[] && A[] == A[] && A[] == A[])
  158. {
  159. puts("Yes");
  160. continue;
  161. }
  162. if(A[] == A[] && A[] != A[] && A[] == A[] && A[] == A[])
  163. {
  164. puts("Yes");
  165. continue;
  166. }
  167. }
  168. if(n1 == )
  169. {
  170. int tag = ;
  171. for(i=;i<=;i++)
  172. {
  173. if(A[i] == A[i+] && A[i+] == A[i+] && A[i+] == A[i+])
  174. {
  175. tag = ;
  176. break;
  177. }
  178. }
  179. if(tag)
  180. {
  181. puts("Yes");
  182. continue;
  183. }
  184. }
  185. //-----------------------------如果不能一次出完
  186. if(Nuke2.size() >= ) //对方有双王,必输
  187. {
  188. puts("No");
  189. continue;
  190. }
  191. if(!Nuke.empty() && Nuke2.empty()) //A有王,B没王
  192. {
  193. puts("Yes");
  194. continue;
  195. }
  196. if(!Nuke.empty() && !Nuke2.empty()) //都有王,看谁的大,如果A小,则不选择出王,继续
  197. {
  198. if(Nuke.top() > Nuke2.top())
  199. {
  200. puts("Yes");
  201. continue;
  202. }
  203. }
  204. if(Four.empty() && !Four2.empty()) //炸弹,如果不能一次出完又没炸弹,那么必会被炸,输
  205. {
  206. puts("No");
  207. continue;
  208. }
  209. if(!Four.empty() && Four2.empty()) //有炸弹出炸弹
  210. {
  211. puts("Yes");
  212. continue;
  213. }
  214. if(!Four.empty() && !Four2.empty()) //都有炸弹,A的如果小,因为不能一次出完,必输
  215. {
  216. if(Four.top() >= Four2.top())
  217. {
  218. puts("Yes");
  219. continue;
  220. }
  221. else
  222. {
  223. puts("No");
  224. continue;
  225. }
  226. }
  227. if(!Tri.empty() && Tri2.empty()) //三个的情况
  228. {
  229. puts("Yes");
  230. continue;
  231. }
  232. if(!Tri.empty() && !Tri2.empty())
  233. {
  234. if(Tri.top() >= Tri2.top())
  235. {
  236. puts("Yes");
  237. continue;
  238. }
  239. else if(n1 >= && n2 <= ) //A有的带,B没得带
  240. {
  241. puts("Yes");
  242. continue;
  243. }
  244. }
  245. if(!Pair.empty() && Pair2.empty()) //对子
  246. {
  247. puts("Yes");
  248. continue;
  249. }
  250. if(!Pair.empty() && !Pair2.empty())
  251. {
  252. if(Pair.top() >= Pair2.top())
  253. {
  254. puts("Yes");
  255. continue;
  256. }
  257. }
  258. if(Single.empty() && !Single2.empty()) //单个牌
  259. {
  260. puts("No");
  261. continue;
  262. }
  263. if(!Single.empty() && Single2.empty())
  264. {
  265. puts("Yes");
  266. continue;
  267. }
  268. if(!Single.empty() && !Single2.empty())
  269. {
  270. if(Single.top() >= Single2.top())
  271. {
  272. puts("Yes");
  273. continue;
  274. }
  275. }
  276. puts("No"); //如果以上都不满足,那么A输了,gg。
  277. }
  278. return ;
  279. }

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

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

    HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...

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

    Fighting the Landlords 大意: 斗地主... . 分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black ...

  3. HDU 4930 Fighting the Landlords(模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 解题报告:斗地主,加了一个四张可以带两张不一样的牌,也可以带一对,判断打出一手牌之后,如果对手没 ...

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

    题目链接 题意 : 玩斗地主,出一把,只要你这一把对方要不了或者你出这一把之后手里没牌了就算你赢. 思路 : 一开始看了第一段以为要出很多次,实际上只问了第一次你能不能赢或者能不能把牌出尽. #inc ...

  5. hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...

  6. hdu4930 Fighting the Landlords(模拟 多校6)

    题目链接:pid=4930">http://acm.hdu.edu.cn/showproblem.php? pid=4930 Fighting the Landlords Time L ...

  7. HDU4930 Fighting the Landlords 模拟

    Fighting the Landlords Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  8. hdu 4930 斗地主恶心模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=4930 就是两个人玩斗地主,有8种牌型,单张,一对,三张,三带一,三带对,四带二,四炸,王炸.问先手能否一次出完牌 ...

  9. HDOJ(HDU) 2109 Fighting for HDU(简单排序比较)

    Problem Description 在上一回,我们让你猜测海东集团用地的形状,你猜对了吗?不管结果如何,都没关系,下面我继续向大家讲解海东集团的发展情况: 在最初的两年里,HDU发展非常迅速,综合 ...

随机推荐

  1. C语言范例学习03-上

    第三章 数据结构 章首:不好意思,这两天要帮家里做一些活儿.而且内容量与操作量也确实大幅提升了.所以写得很慢. 不过,从今天开始.我写的东西,许多都是之前没怎么学的了.所以速度会慢下来,同时写得也会详 ...

  2. 关于setInterval和setTImeout中的this指向问题

    前些天在练习写一个小例子的时候用到了定时器,发现在setInterval和setTimeout中传入函数时,函数中的this会指向window对象,如下例: var num = 0; function ...

  3. JS创建对象、继承原型、ES6中class继承

    面向对象编程:java中对象的两个基本概念:1.类:类是对象的模板,比如说Leader 这个是泛称领导,并不特指谁.2:实例:实例是根据类创建的对象,根据类Leader可以创建出很多实例:liyi,y ...

  4. 移动端H5---页面适配问题详谈(一)

    一.前言 昨天唠叨了哈没用的,今天说点有用的把.先说一下响应式布局吧,我一直认为响应式布局的分项目,一下布局简单得项目做响应式还是可以可以得.例如博客.后台管理系统等.但是有些会认为响应式很牛逼,尤其 ...

  5. git学习笔记2

    工作区和暂存区 Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 先来看名词解释. 工作区(Working Directory) 就是你在电脑里能看到的目录,比如我的github文件 ...

  6. 基础学习day12--多线程一线程之间的通信和常用方法

    一.线程之间的通信 1.1.线程之间的通信方法 多个线程在处理统一资源,但是任务却不同,这时候就需要线程间通信.    等待/唤醒机制涉及的方法:    1. wait():让线程处于冻结状态,被wa ...

  7. 菜鸟教程 Python100例 之实例29

    学习编程的路,走得好艰辛... 为了巩固基础知识,把菜鸟教程网上的实例拿来练习.. 在做到实例29时,看了网站给出的代码,觉得可以加强一下功能,不由得动了一下脑筋,如下: 原文题目: 题目:给一个不多 ...

  8. bsearch

    在java中为了避免 low+high溢出,可以用无符号右移:正数高位补0,负数高位补1 int mid = (low + high) >>> 1; 如果是在c++中,那么需要先转换 ...

  9. Windows Server 2008 下ASP程序连接ORACLE数据库驱动错误

    今天开发那边升级.改造系统过程中,在测试服务器碰到关于ASP程序连接ORACLE数据库的小问题,虽然是小问题,但是整起来真要命啊,花了不少时间,主要是ASP程序啊,这种上古神器,哥还是当年毕业的时候弄 ...

  10. sql server 导出的datetime结果 CAST(0x00009E0E0095524F AS DateTime) 如何向mysql,oracle等数据库进行转换

    1. 处理 sql server 导出的 datetime 类型的字段 在进行sql server向mysql等其他数据进行迁移数据时,会发现使用sql server导出的datetime类型的结果是 ...