/* THE PROGRAM IS MADE BY PYY */
/*----------------------------------------------------------------------------//
Copyright (c) 2011 panyanyany All rights reserved.
URL : http://acm.hdu.edu.cn/showproblem.php?pid=1528
Name : 1528 Card Game Cheater
Date : Saturday, August 27, 2011
Time Stage : two hours
Result:
4502995 2011-08-27 16:50:52 Accepted 1528
0MS 236K 2156 B
C++ pyy
Test Data:
Review:
一开始写得很复杂,其实只要在输入的时候把牌的面值和花色转为整数存在一个整型值
里就行了,这样比较起来方便些。
感觉这个貌似是最大匹配,貌似还是单向的?从 eve 的边集出发,向 adam 的边集前进,
如果 eve 比 adam 大则表示此路可通,否则不可通。求这种通路的最大数量。
这样感觉起来,应该是个单向的最大匹配了吧?小弟不才,对二分图理解甚少,只能这样
猜测了……
//----------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define FALSE 0
#define TRUE 1
#define infinity 0x0f0f0f0f
#define minus_inf 0x80808080
#define MAXSIZE 27
int tcase, k ;
int cover[MAXSIZE], link[MAXSIZE], adam[MAXSIZE], eve[MAXSIZE] ;
int makeInt (char c)
{
int sign = 10, d ;
if ('0' < c && c <= '9')
d = c - '0' ;
else if (c == 'T') d = 10 ;
else if (c == 'J') d = 11 ;
else if (c == 'Q') d = 12 ;
else if (c == 'K') d = 13 ;
else if (c == 'A') d = 14 ;
else {
sign = 1 ;
if (c == 'C') d = 1 ;
else if (c == 'D') d = 2 ;
else if (c == 'S') d = 3 ;
else if (c == 'H') d = 4 ;
}
return d * sign ;
}
int find (int cur)
{
int i, j ;
for (i = 0 ; i < k ; ++i)
{
if (cover[i] == FALSE && eve[cur] > adam[i])
{
cover[i] = TRUE ;
if (link[i] == -1 || find (link[i]))
{
link[i] = cur ;
return 1 ;
}
}
}
return 0 ;
}
int main ()
{
char a, b, c ;
int i, j, sum ;
while (scanf ("%d", &tcase) != EOF)
{
while (tcase--)
{
scanf ("%d", &k) ;
getchar () ;
for (i = 0 ; i < k ; ++i)
{
scanf ("%c%c", &a, &b) ;
getchar () ;
adam[i] = makeInt (a) + makeInt (b) ;
}
for (i = 0 ; i < k ; ++i)
{
scanf ("%c%c", &a, &b) ;
getchar () ;
eve[i] = makeInt (a) + makeInt (b) ;
}
sum = 0 ;
memset (link, -1, sizeof (link)) ;
for (i = 0 ; i < k ; ++i)
{
memset (cover, 0, sizeof (cover)) ;
sum += find (i) ;
}
printf ("%d\n", sum) ;
}
}
return 0 ;
}
杭电 hdu 1528 Card Game Cheater (二分图,最大匹配)
最新推荐文章于 2019-11-11 14:38:45 发布