赤裸裸的二分匹配。。。注意处理好输入
#include<cstdlib>
#include<iostream>
#include<cstring>
using namespace std;
int mj[28][28];
int flag[28];
int result[28];
int n;
bool Find(int x)
{
int j;
for(j=1;j<=n;j++)
{
if(mj[x][j]!=0&&flag[j]==0)
{
flag[j]=1;
if(result[j]==0||Find(result[j]))
{
result[j]=x;
return true;
}
}
}
return false;
}
int main()
{
int t,i,j,ans,x1[28],x2[28],y1[28],y2[28];
char ch[4];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(mj,0,sizeof(mj));
memset(result,0,sizeof(result));
for(i=1;i<=n;i++)
{
scanf("%s",ch);
if(ch[0]=='A') x1[i]=14;
else if(ch[0]=='K') x1[i]=13;
else if(ch[0]=='Q') x1[i]=12;
else if(ch[0]=='J') x1[i]=11;
else if(ch[0]=='T') x1[i]=10;
else x1[i]=ch[0]-'0';
if(ch[1]=='H') y1[i]=4;
else if(ch[1]=='S') y1[i]=3;
else if(ch[1]=='D') y1[i]=2;
else y1[i]=1;
}
for(i=1;i<=n;i++)
{
scanf("%s",ch);
if(ch[0]=='A') x2[i]=14;
else if(ch[0]=='K') x2[i]=13;
else if(ch[0]=='Q') x2[i]=12;
else if(ch[0]=='J') x2[i]=11;
else if(ch[0]=='T') x2[i]=10;
else x2[i]=ch[0]-'0';
if(ch[1]=='H') y2[i]=4;
else if(ch[1]=='S') y2[i]=3;
else if(ch[1]=='D') y2[i]=2;
else y2[i]=1;
}
ans=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(x2[i]>x1[j]||(x2[i]==x1[j]&&y2[i]>y1[j]))
mj[i][j]=1;
}
}
for(i=1;i<=n;i++)
{
memset(flag,0,sizeof(flag));
if(Find(i)) ans++;
}
printf("%d\n",ans);
}
return 0;
}