http://acm.hdu.edu.cn/showproblem.php?pid=1528

Card Game Cheater

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1559    Accepted Submission(s): 820

Problem Description
Adam and Eve play a card game using a regular deck of 52 cards. The rules are simple. The players sit on opposite sides of a table, facing each other. Each player gets k cards from the deck and, after looking at them, places the cards face down in a row on the table. Adam’s cards are numbered from 1 to k from his left, and Eve’s cards are numbered 1 to k from her right (so Eve’s i:th card is opposite Adam’s i:th card). The cards are turned face up, and points are awarded as follows (for each i ∈ {1, . . . , k}):

If Adam’s i:th card beats Eve’s i:th card, then Adam gets one point.

If Eve’s i:th card beats Adam’s i:th card, then Eve gets one point.

A card with higher value always beats a card with a lower value: a three beats a two, a four beats a three and a two, etc. An ace beats every card except (possibly) another ace.

If the two i:th cards have the same value, then the suit determines who wins: hearts beats all other suits, spades beats all suits except hearts, diamond beats only clubs, and clubs does not beat any suit.

For example, the ten of spades beats the ten of diamonds but not the Jack of clubs.

This ought to be a game of chance, but lately Eve is winning most of the time, and the reason is that she has started to use marked cards. In other words, she knows which cards Adam has on the table before he turns them face up. Using this information she orders her own cards so that she gets as many points as possible.

Your task is to, given Adam’s and Eve’s cards, determine how many points Eve will get if she plays optimally.

 
Input
There will be several test cases. The first line of input will contain a single positive integer N giving the number of test cases. After that line follow the test cases.

Each test case starts with a line with a single positive integer k <= 26 which is the number of cards each player gets. The next line describes the k cards Adam has placed on the table, left to right. The next line describes the k cards Eve has (but she has not yet placed them on the table). A card is described by two characters, the first one being its value (2, 3, 4, 5, 6, 7, 8 ,9, T, J, Q, K, or A), and the second one being its suit (C, D, S, or H). Cards are separated by white spaces. So if Adam’s cards are the ten of clubs, the two of hearts, and the Jack of diamonds, that could be described by the line

TC 2H JD

 
Output
For each test case output a single line with the number of points Eve gets if she picks the optimal way to arrange her cards on the table.

 
Sample Input
3
1
JD
JH
2
5D TC
4C 5H
3
2H 3H 4H
2D 3D 4D
 
Sample Output
1
1
2
 
 
在多校联萌的比赛里, 我也读这题了, 可惜读了一半放弃了, 其实就是简单构一下图, 然后用匈牙利算法匹配一下就OK了下面简单说下思路吧!!!
 
 每张牌有两个字母来表示, 第一个代表价值(它的价值依次是(2, 3, 4, 5, 6, 7, 8 ,9, T, J, Q, K, or A)但是是递增的), 第二个代表花色(大小(C, D, S, or H)也是递增的)
 他想要尽可能的多赢, 用匈牙利算法来求最多可以赢几张牌
 
 
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<algorithm>
  4. #include<stdlib.h>
  5. #include<string.h>
  6. #include<map>
  7. using namespace std;
  8.  
  9. #define N 110
  10.  
  11. char s1[N][], s2[N][];
  12. int G[N][N], n, used[N], p[N];
  13.  
  14. map<char, int>G1, G2;
  15.  
  16. void InIt()
  17. {
  18. G1[''] = ; G2['C'] = ;
  19. G1[''] = ; G2['D'] = ;
  20. G1[''] = ; G2['S'] = ;
  21. G1[''] = ; G2['H'] = ;
  22. G1[''] = ;
  23. G1[''] = ;
  24. G1[''] = ;
  25. G1[''] = ;
  26. G1['T'] = ;
  27. G1['J'] = ;
  28. G1['Q'] = ;
  29. G1['K'] = ;
  30. G1['A'] = ;
  31. }
  32.  
  33. int Judge(char a[], char b[])
  34. {
  35. if(G1[b[]]>G1[a[]])
  36. return ;
  37. if(b[] == a[] && G2[b[]]>G2[a[]])
  38. return ;
  39.  
  40. return ;
  41. }
  42.  
  43. int Find(int u)
  44. {
  45. for(int i=; i<=n; i++)
  46. {
  47. if(G[u][i] && !used[i])
  48. {
  49. used[i] = ;
  50. if(!p[i] || Find(p[i]))
  51. {
  52. p[i] = u;
  53. return ;
  54. }
  55. }
  56. }
  57. return ;
  58. }
  59.  
  60. int hungary()
  61. {
  62. int ans = ;
  63.  
  64. memset(p, , sizeof(p));
  65. for(int i=; i<=n; i++)
  66. {
  67. memset(used, , sizeof(used));
  68. int t = Find(i);
  69. if(t) ans ++ ;
  70. }
  71.  
  72. return ans;
  73. }
  74.  
  75. int main()
  76. {
  77. int T;
  78.  
  79. scanf("%d", &T);
  80.  
  81. InIt();
  82.  
  83. while(T--)
  84. {
  85. int i, j;
  86.  
  87. scanf("%d", &n);
  88.  
  89. memset(s1, , sizeof(s1));
  90. memset(s2, , sizeof(s2));
  91. memset(G, , sizeof(G));
  92.  
  93. for(i=; i<=n; i++)
  94. scanf("%s", s1[i]);
  95. for(i=; i<=n; i++)
  96. scanf("%s", s2[i]);
  97.  
  98. for(i=; i<=n; i++) ///构图
  99. for(j=; j<=n; j++)
  100. {
  101. int t = Judge(s1[i], s2[j]);
  102. if(t)
  103. G[i][j] = ;
  104. }
  105.  
  106. int ans = hungary();
  107.  
  108. printf("%d\n", ans);
  109. }
  110. return ;
  111. }

(简单匹配)Card Game Cheater -- hdu --1528的更多相关文章

  1. HDOJ 1528 Card Game Cheater

    版权声明:来自: 码代码的猿猿的AC之路 http://blog.csdn.net/ck_boss https://blog.csdn.net/u012797220/article/details/3 ...

  2. hdu 1528 Card Game Cheater (二分匹配)

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. (hdu step 6.3.5)Card Game Cheater(匹配的最大数:a与b打牌,问b赢a多少次)

    称号: Card Game Cheater Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  4. Card Game Cheater(贪心+二分匹配)

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. Card Game Cheater

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. HDU 1528 贪心模拟/二分图

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. hdu----(1528)Card Game Cheater(最大匹配/贪心)

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. hdu 1528 Card Game Cheater ( 二分图匹配 )

    题目:点击打开链接 题意:两个人纸牌游戏,牌大的人得分.牌大:2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < ...

  9. POJ 2062 HDU 1528 ZOJ 2223 Card Game Cheater

    水题,感觉和田忌赛马差不多 #include<cstdio> #include<cstring> #include<cmath> #include<algor ...

随机推荐

  1. json等序列化模块 异常处理

    今日学习内容如下: 1.序列化模块 什么叫序列化——将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化. 比如,我们在python代码中计算的一个数据需要给另外一段程序使用,那我们怎么给? 现 ...

  2. DevExpress XPO 开发指南 简要

    最近在看devexpress   安装程序中的代码Demos ..  C:\Users\Public\Documents\DevExpress Demos 16.1\Components\WinFor ...

  3. kali安全工具

    http://www.kali.org.cn/ Kali linux下载安装 (27) kali linux是backtrack的最新代号,或者叫新版本的backtrack,欢迎下载使用. 908 / ...

  4. mount重新挂载为写模式

    mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system mount -o remount,rw -t rootfs rootfs /

  5. Fedora : multilib version problems found

    摘自:https://smjrifle.net/fedora-fix-multilib-version-problems/ This error was due to duplicate packag ...

  6. Delphi各种Socket组件的模式和模型

    Delphi各种Socket组件的模式和模型 Delphi的大多数书籍里面都没有提到delphi的各种socket通信组件的模式和模型,有的书只讲解了windows的socket模式和模型,并没有归纳 ...

  7. Virtual Machine Kernel Panic : Not Syncing : VFS : Unable To Mount Root FS On Unknown-Block (0,0)

    Virtual Machine Kernel Panic : Not Syncing : VFS : Unable To Mount Root FS On Unknown-Block (0,0) 33 ...

  8. Spring 系列教程之 bean 的加载

    Spring 系列教程之 bean 的加载 经过前面的分析,我们终于结束了对 XML 配置文件的解析,接下来将会面临更大的挑战,就是对 bean 加载的探索.bean 加载的功能实现远比 bean 的 ...

  9. 繁体简体转化_langconv.py

    from copy import deepcopyimport re try: import psyco psyco.full()except: pass try: from zh_wiki impo ...

  10. Maven构建JavaWeb

    查看java和mvn版本 java -version mvn -v D:\software\yiibai\spring-1.4.3.RELEASE>java -versionjava versi ...