HDOJ 题目1528 Card Game Cheater(二分图最小点覆盖)

Card Game Cheater

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1357    Accepted Submission(s): 722

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

Northwestern Europe 2004

Recommend

8600   |   We have carefully selected several similar problems for you:  1507 1533 1530 1526 2768

题目意思是给一副扑克牌,点数大小从2-A,T代表的是10,A最大..然后四种花色分别是C、D、S、H,如果点数相同的话C<D<S<H。两个无聊的人开始用这幅52张的扑克牌玩游戏,每次两个人取k张牌,没有两张一模一样的牌,问第二个人可以赢第一个人多少次...

ac代码

#include<stdio.h>
#include<string.h>
int a[1010],b[1010],map[1010][1010],link[1010],vis[1010],n;
int fun(char *s)
{
	int ans;
	if(s[0]=='T')
		ans=10;
	else
		if(s[0]=='J')
			ans=11;
		else
			if(s[0]=='Q')
				ans=12;
			else
				if(s[0]=='K')
					ans=13;
				else
					if(s[0]=='A')
						ans=14;
					else
						ans=s[0]-'0';
	if(s[1]=='C')
		ans=ans*10+1;
	else
		if(s[1]=='D')
			ans=ans*10+2;
		else
			if(s[1]=='S')
				ans=ans*10+3;
			else
				if(s[1]=='H')
					ans=ans*10+4;
	return ans;
}
int dfs(int x)
{
	int i;
	for(i=1;i<=n;i++)
	{
		if(!vis[i]&&map[x][i])
		{
			vis[i]=1;
			if(link[i]==-1||dfs(link[i]))
			{
				link[i]=x;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int i,j;
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		{
			char s[10];
			scanf("%s",s);
			a[i]=fun(s);
		}
		for(i=1;i<=n;i++)
		{
			char s[10];
			scanf("%s",s);
			b[i]=fun(s);
		}
		memset(map,0,sizeof(map));
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(a[i]<b[j])
				{
					map[i][j]=1;
				}
			}
		}
		memset(link,-1,sizeof(link));
		int ans=0;
		for(i=1;i<=n;i++)
		{
			memset(vis,0,sizeof(vis));
			if(dfs(i))
				ans++;
		}
		printf("%d\n",ans);
	}
}
时间: 2024-10-12 23:52:43

HDOJ 题目1528 Card Game Cheater(二分图最小点覆盖)的相关文章

HDOJ 1528 Card Game Cheater

简单二分图匹配.... Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1073    Accepted Submission(s): 565 Problem Description Adam and Eve play a card game using a regular deck of 52 ca

POJ2226 Muddy Fields(二分图最小点覆盖集)

题目给张R×C的地图,地图上*表示泥地..表示草地,问最少要几块宽1长任意木板才能盖住所有泥地,木板可以重合但不能盖住草地. 把所有行和列连续的泥地(可以放一块木板铺满的)看作点且行和列连续泥地分别作为XY部,每一块泥地看作边.这样就构造出了一个二分图. 那么,问题就是在这个二分图中就是选出最少的点覆盖所有的边,即二分图最小点覆盖集,而二分图最小点覆盖集=二分图最大匹配. 1 #include<cstdio> 2 #include<cstring> 3 #include<qu

POJ3041 Asteroids【二分图最小点覆盖】

题目链接: http://poj.org/problem?id=3041 题目大意: 有一个N*N的矩阵,有些格子上有障碍物(坐标为(x,y) ),在消除这些障碍物的时候,可以一次性消除 该障碍物同一行所有的障碍物,或是一次性消除该障碍物同一列所有的障碍物.只能选择清理该行或是 清理该列.问:最小进行多少次消除,就可以清理所有的障碍物. 思路: 可以将每一行当做一个点,这样总共有N个点,作为二分图的一边.将每一列当做一个点,这样又有N 个点,作为二分图的另一边.将有障碍物的行点和列点连接起来,每

POJ1325_Machine Schedule(二分图/最小点覆盖=最大匹配)

解题报告 http://blog.csdn.net/juncoder/article/details/38147135 题目传送门 题意: A机器有n个模式,B机器有m个模式,每个作业可以在任何机器的特定模式下工作,转换模式需要耗时,求最小耗时 思路: 把AB两机器的模式当成二分图顶点,模式之间的连线就是某个作业可以在该两个模式下工作,就转换成求最小点覆盖,用最少的点覆盖最多的边. 最小点覆盖=最大匹配 #include <queue> #include <cmath> #incl

HDU2119_Matrix(二分图/最小点覆盖=最大匹配)

解题报告 题目传送门 题意: 题意类似与POJ3041 思路: 见POJ3041解题报告 最小点覆盖. #include <iostream> #include <cstring> #include <cstdio> using namespace std; int mmap[110][110],vis[110],pre[110],n,m; int dfs(int x) { for(int i=1; i<=m; i++) { if(!vis[i]&&

hihoCoder #1127:二分图最小点覆盖和最大独立集

题目大意:求二分图最小点覆盖和最大独立集. 题目分析:如果选中一个点,那么与这个点相连的所有边都被覆盖,使所有边都被覆盖的最小点集称为最小点覆盖,它等于最大匹配:任意两个点之间都没有边相连的最大点集称为最大独立集,它等于总节点数减去最大匹配数. 代码如下: # include<iostream> # include<cstdio> # include<cmath> # include<vector> # include<list> # inclu

hihocoder 第三十四周 二分图三&#183;二分图最小点覆盖和最大独立集

题目1 : 二分图三·二分图最小点覆盖和最大独立集 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在上次安排完相亲之后又过了挺长时间,大家好像都差不多见过面了.不过相亲这个事不是说那么容易的,所以Nettle的姑姑打算收集一下之前的情况并再安排一次相亲.所以现在摆在Nettle面前的有2个问题: 1.姑姑想要了解之前所有相亲的情况.对于任一个一次相亲,只要跟参与相亲的两人交流就可以得到这次相亲的情况.如果一个人参加了多次相亲,那么跟他交流就可以知道这几次相亲的情况

POJ1325 Machine Schedule【二分图最小点覆盖】

题目链接: http://poj.org/problem?id=1325 题目大意: 有两台机器A和B,机器A有N种不同的模式,编号为0~N-1.机器B有M种不同的模式,编号为0~M-1. 在一开始的时候,机器A和B都处于0模式.现在需要用两台机器来处理K项任务,任务编号为0~K-1.每 一项任务都可以在A或B的指定状态下完成.例如任务1可以在机器A的2模式下完成,也可以在机器B的4 模式下完成.对于第i想任务用(i,x,y)来表示第i项任务可以在机器A的x模式下或机器B的y模式下完成. 为了完

poj 2226 二分图 最小点覆盖 , 最大流

题目就是问如何用最小的板覆盖所有的草地.可以横着放,也可以竖着放,允许一个草地放多个点. 建图方法就是 每个横向的草地作为X,纵向连续的草地作为Y.     X连接Y的边表示,  这里有他们的公共点.. 很显然,覆盖所有草地,就是覆盖所有的边 ,二分图中,最小点覆盖 = 最大匹配 = =其实如果存在一条边未被选中的节点覆盖,则必然存在一条对应的增广路径 //tpl //ipqhjjybj_tpl.h //header.h #include <cstdio> #include <cstdl