hdu 1528 Card Game Cheater

题意:两个人打牌,同一位置谁牌面大谁得一分。但是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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值