题意:两个人打牌,同一位置谁牌面大谁得一分。但是EVA知道Adam的牌所以可以调整自己的牌。
对于每张EVA的牌遍历Adam的牌,如果EVA的大就从连一条边,最后求一次最大匹配即可。
二分图的存边数组记得要清空= =
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
int a[30], b[30];
vector<int> v[30];
int n;
int vis[30], link[30];
bool dfs(int u)
{
for( int i = 0; i < v[u].size(); i++ )
{
int to = v[u][i];
if( !vis[to])
{
vis[to] = 1;
if( link[to] == -1 || dfs( link[to] ) )
{
link[to] = u;
return 1;
}
}
}
return 0;
}
int main()
{
int tot;
scanf("%d", &tot);
while(tot--)
{
scanf("%d", &n);
for( int i = 1; i <= n; i++ )
v[i].clear();
char c[5];
for ( int i = 1; i <= n; i++ )
{
scanf("%s", c);
int x = 0;
if(c[0] >= '2' && c[0] <= '9')
x = c[0] - '0';
else if(c[0] == 'T')
x = 10;
else if(c[0] == 'J')
x = 11;
else if(c[0] == 'Q')
x = 12;
else if(c[0] == 'K')
x = 13;
else if(c[0] == 'A')
x = 14;
x *= 10;
if( c[1] == 'C' )
x++;
else if( c[1] == 'D')
x += 2;
else if( c[1] == 'S')
x += 3;
else
x += 4;
a[i] = x;
}
for ( int i = 1; i <= n; i++ )
{
scanf("%s", c);
int x = 0;
if(c[0] >= '2' && c[0] <= '9')
x = c[0] - '0';
else if(c[0] == 'T')
x = 10;
else if(c[0] == 'J')
x = 11;
else if(c[0] == 'Q')
x = 12;
else if(c[0] == 'K')
x = 13;
else if(c[0] == 'A')
x = 14;
x *= 10;
if( c[1] == 'C' )
x++;
else if( c[1] == 'D')
x += 2;
else if( c[1] == 'S')
x += 3;
else
x += 4;
b[i] = x;
}
for( int j = 1; j <= n; j++ )
{
for( int i = 1; i <= n; i++ )
{
if(b[i] > a[j])
{
v[i].push_back(j);
}
}
}
memset(link, -1, sizeof(link));
int ans = 0;
for( int i = 1; i <= n; i++ )
{
memset(vis, 0, sizeof(vis));
ans += dfs(i);
}
printf("%d\n", ans);
}
return 0;
}