HDU-1528-Card Game Cheater(二分图匹配)

链接:https://vjudge.net/problem/HDU-1528

题意:

Adam and Eve play a card game using a regular deck of 52 cards. The rules are simple. The players sit on opposite sides of a table, facing each other. Each player gets k cards from the deck and, after looking at them, places the cards face down in a row on the table. Adam’s cards are numbered from 1 to k from his left, and Eve’s cards are numbered 1 to k from her right (so Eve’s i:th card is opposite Adam’s i:th card). The cards are turned face up, and points are awarded as follows (for each i ∈ {1, . . . , k}): 
If Adam’s i:th card beats Eve’s i:th card, then Adam gets one point. 
If Eve’s i:th card beats Adam’s i:th card, then Eve gets one point. 
A card with higher value always beats a card with a lower value: a three beats a two, a four beats a three and a two, etc. An ace beats every card except (possibly) another ace. 
If the two i:th cards have the same value, then the suit determines who wins: hearts beats all other suits, spades beats all suits except hearts, diamond beats only clubs, and clubs does not beat any suit. 
For example, the ten of spades beats the ten of diamonds but not the Jack of clubs. 
This ought to be a game of chance, but lately Eve is winning most of the time, and the reason is that she has started to use marked cards. In other words, she knows which cards Adam has on the table before he turns them face up. Using this information she orders her own cards so that she gets as many points as possible. 

Your task is to, given Adam’s and Eve’s cards, determine how many points Eve will get if she plays optimally. 

a和b有n张牌,求最多有几组b的牌比a的牌大。

思路:

二分图匹配,最大匹配。

建图比较烦,我是用结构体先记录牌,再比大小建图,最后直接最大匹配。

代码:

#include <iostream>
#include <memory.h>
#include <string>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <cstdio>
#include <set>
#include <iterator>
#include <cstring>
using namespace std;

typedef long long LL;
const int MAXN = 1e3+10;
int Next[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

struct Node
{
    string _card;
    int l;
    int r;
    void Init()
    {
        if (isdigit(_card[0]))
            l = _card[0] - '0';
        else if (_card[0] == 'T')
            l = 10;
        else if (_card[0] == 'J')
            l = 11;
        else if (_card[0] == 'Q')
            l = 12;
        else if (_card[0] == 'K')
            l = 13;
        else
            l = 14;
        if (_card[1] == 'H')
            r = 4;
        else if (_card[1] == 'S')
            r = 3;
        else if (_card[1] == 'D')
            r = 2;
        else
            r = 1;
    }
    bool operator > (const Node & that) const
    {
        if (this->l  != that.l)
            return this->l > that.l;
        return this->r > that.r;
    }
}Adam[30], Eve[30];

vector<int> G[MAXN];
int Dis[200][200];
int Link[MAXN], Vis[MAXN];
int n, m, k;
int mid;

bool Dfs(int x)
{
    for (int i = 0;i < G[x].size();i++)
    {
        int node = G[x][i];
        if (Vis[node] == 0)
        {
            Vis[node] = 1;
            if (Link[node] == -1 || Dfs(Link[node]))
            {
                Link[node] = x;
                return true;
            }
        }
    }
    return false;
}

int Solve()
{
    memset(Link, -1, sizeof(Link));
    int cnt = 0;
    for (int i = 1;i <= n;i++)
    {
        memset(Vis, 0, sizeof(Vis));
        if (Dfs(i))
            cnt++;
    }
    return cnt;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n;
        for (int i = 1;i <= n;i++)
            G[i].clear();
        for (int i = 1;i <= n;i++)
            cin >> Adam[i]._card, Adam[i].Init();
        for (int i = 1;i <= n;i++)
            cin >> Eve[i]._card, Eve[i].Init();
        for (int i = 1;i <= n;i++)
        {
            for (int j = 1;j <= n;j++)
            {
                if (Eve[i] > Adam[j])
                {
                    G[i].push_back(j);
                }
            }
        }
        int res = Solve();
        cout << res << endl;
    }

    return 0;
}

  

转载于:https://www.cnblogs.com/YDDDD/p/10871846.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值