hdu 1528 Card Game Cheater (二分匹配)

时间:2022-10-15 10:06:06

Card Game Cheater

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

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
 
Source
 
Recommend
8600   |   We have carefully selected several similar problems for you:  1507 1498 1533 1083 1530 
 

题意:

分别给出k张牌,第一个字符为点数,第二个为花色,求第二组和第一组怎么搭配可以获得最多的分数。(比之大可得一分)

二分匹配:

用map记录牌的点数,然后暴力出边,在进行二分匹配得解。

 //0MS    256K    1366 B    C++
#include<iostream>
#include<map>
#define N 55
using namespace std;
int g[N][N];
int match[N];
int vis[N];
int n;
map<char,int>M;
void init()
{
M['']=;
M['']=;
M['']=;
M['']=;
M['']=;
M['']=;
M['']=;
M['']=;
M['T']=;
M['J']=;
M['Q']=;
M['K']=;
M['A']=;
M['C']=;
M['D']=;
M['S']=;
M['H']=;
}
int dfs(int x)
{
for(int i=;i<n;i++){
if(!vis[i] && g[x][i]){
vis[i]=;
if(match[i]==- || dfs(match[i])){
match[i]=x;
return ;
}
}
}
return ;
}
int hungary()
{
int ret=;
memset(match,-,sizeof(match));
for(int i=;i<n;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
int t;
char a[N][],b[N][];
init();
scanf("%d",&t);
while(t--)
{
memset(g,,sizeof(g));
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%s",a[i]);
for(int i=;i<n;i++){
scanf("%s",b[i]);
for(int j=;j<n;j++)
if(M[a[j][]]+M[a[j][]]<M[b[i][]]+M[b[i][]])
g[i][j]=;
}
printf("%d\n",hungary());
}
return ;
}

hdu 1528 Card Game Cheater (二分匹配)的更多相关文章

  1. hdu 1528 Card Game Cheater &lpar; 二分图匹配 &rpar;

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

  2. hdu 1068 Girls and Boys &lpar;二分匹配&rpar;

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDU 2063 过山车&lpar;二分匹配入门&rpar;

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...

  4. HDU - 1045 Fire Net(二分匹配)

    Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...

  5. HDOJ 1528 Card Game Cheater

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

  6. hdu 4619 Warm up 2 &lpar;二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 题意: 平面上有一些1×2的骨牌,每张骨牌要么水平放置,要么竖直放置,并且保证同方向放置的骨牌不 ...

  7. HDU 2063 过山车 二分匹配

    解题报告:有m个女生和n个男生要结成伴坐过山车,每个女生都有几个自己想选择的男生,然后要你确定最多能组成多少对组合. 最裸的一个二分匹配,这是我第一次写二分匹配,给我最大的感受就是看那些人讲的匈牙利算 ...

  8. HDU - 1068 Girls and Boys&lpar;二分匹配---最大独立集&rpar;

    题意:给出每个学生的标号及与其有缘分成为情侣的人的标号,求一个最大集合,集合中任意两个人都没有缘分成为情侣. 分析: 1.若两人有缘分,则可以连一条边,本题是求一个最大集合,集合中任意两点都不相连,即 ...

  9. hdu 1150 Machine Schedule &lpar;经典二分匹配&rpar;

    //A组n人 B组m人 //最多有多少人匹配 每人仅仅有匹配一次 # include<stdio.h> # include<string.h> # include<alg ...

随机推荐

  1. wordpress修改上传文件大小限制

    在为有的客户搭建 WordPress 网站时,有时会遇到因为所在的服务器限制了上传文件大小而无法上传较大的附件,WordPress的媒体文件上传可以看到,大多数都是2MB或者8MB.如果是图片的话可能 ...

  2. QUnit使用笔记-5简化编写

    在测试中,如果用到了大量相同的方法返回判断结果,可以将他们简化; 使用push(): push( result/*boolean,result of assert*/, actual, /*objec ...

  3. Java父线程&lpar;或是主线程&rpar;等待所有子线程退出

    static void testLock1(){ final AtomicInteger waitCount = new AtomicInteger(30000); final Object wait ...

  4. 算法-java代码实现堆排序

    堆排序 第7节 堆排序练习题 对于一个int数组,请编写一个堆排序算法,对数组元素排序. 给定一个int数组A及数组的大小n,请返回排序后的数组. 测试样例: [1,2,3,5,2,3],6 [1,2 ...

  5. java容器类3:set&sol;HastSet&sol;MapSet深入解读

    介绍 Set:集合,是一个不包含重复数据的集合.(A collection that contains no duplicate elements. ) set中最多包含一个null元素,否者包含了两 ...

  6. VS2017 启动调试报错无法启动程序 当前状态中非法

    昨天还可以使用,今天就莫名报了这个错误,百度了一下: 1. 第一种尝试方法是右击解决方案中的项目(图标有带球的),打开属性选择“WEB”选项,修改特定页为Home,结果还是报错. 2.我又关闭Wind ...

  7. Spring系列之AOP的原理及手动实现

    目录 Spring系列之IOC的原理及手动实现 Spring系列之DI的原理及手动实现 引入 到目前为止,我们已经完成了简易的IOC和DI的功能,虽然相比如Spring来说肯定是非常简陋的,但是毕竟我 ...

  8. maridb 10&period;3 主从复制&comma;待机情况下从库 cpu 占用率高的处理方法

    发现两台从库,一直都在CPU 占用率 60% 90% 中浮动, 但是写库却很正常.搜了一大把没找到答案,把参数测试了一下得出以下结论 slave  my.cnf 添加如下参数 #只读模式 read_o ...

  9. 获取url参数的方法&lpar;web&rpar;

    //获取url参数的方法(web) function GetQueryString(name) {     var reg = new RegExp("(^|&)" + n ...

  10. 安装memcached服务 和 php 安装memcache扩展

    这是所有的命令,至于哪个命令是干嘛的自己悟去吧  ,顺便穿插一些知识点 安装libevent cd /home/ wget  http://www.monkey.org/~provos/libeven ...