HDU-1528/1962 Card Game Cheater
两组牌中两张牌相比能赢的就连,后求最大匹配。
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <fstream>
#include <iostream>
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define clr(x, c) memset(x, c, sizeof(x))
#define N 32
#define MAX 1<<30
#define ll long long
using namespace std;
int read()
{
int x=0, f=1; char ch=getchar();
while (ch<'0' || ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
return x*f;
}
int read2()
{
char s[5]; scanf("%s", s); int a;
if (s[0]=='T') a=32;
else if (s[0]=='J') a=36;
else if (s[0]=='Q') a=40;
else if (s[0]=='K') a=44;
else if (s[0]=='A') a=48;
else a=(s[0]-'2')*4;
if (s[1]=='H') a+=3;
else if (s[1]=='S') a+=2;
else if (s[1]=='D') a+=1;
return a;
}
struct edge{int y, n;} e[N*N]; int fir[N], en;
int n, ka[N], kb[N], k[N], ans;
bool b[N];
void Add(int x, int y) { en++, e[en].y=y, e[en].n=fir[x], fir[x]=en; }
bool Find(int x)
{
int o=fir[x], y=e[o].y;
while (o)
{
if (!b[y])
{
b[y]=1; if (!k[y] || Find(k[y])) { k[y]=x; return true; }
}
o=e[o].n, y=e[o].y;
}
return false;
}
int main()
{
int t=read(); while (t--)
{
clr(fir, 0); clr(k, 0); en=ans=0;
n=read();
rep(i, 1, n) ka[i]=read2();
rep(i, 1, n) kb[i]=read2();
rep(i, 1, n) rep(j, 1, n) if (kb[j] > ka[i]) Add(i, j);
rep(i, 1, n)
{
clr(b, 0); if (Find(i)) ans++;
}
printf("%d\n", ans);
}
return 0;
}

浙公网安备 33010602011771号