Card Game Cheater---hdu1528(二分匹配)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1528

题意就是给有两个人有n张牌第二个人知道第一个人的牌的序列;
然后尽可能的让自己的更高的分,求这个最高分;
就是对方拿一张牌出来自己拿一张比他大的就得1分,如果相等就按红桃>黑桃>方块>梅花进行比较;

建图求最大匹配;

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define N 220

int n, maps[N][N], vis[N], used[N];

struct node
{
    int v,s;///v是纸牌的价值,s类型1:梅花  2:方块  3:黑桃  4:红桃;
} a[N], b[N];

void change(char s[], node &a)///传入地址才能改变它的值;
{
    if(s[0]<=‘9‘&&s[0]>=‘2‘)a.v=s[0]-‘0‘;
    if(s[0]==‘A‘)a.v=14;///A是最大的牌;;;;;
    if(s[0]==‘T‘)a.v=10;
    if(s[0]==‘J‘)a.v=11;
    if(s[0]==‘Q‘)a.v=12;
    if(s[0]==‘K‘)a.v=13;

    if(s[1]==‘H‘)a.s=4;
    if(s[1]==‘S‘)a.s=3;
    if(s[1]==‘D‘)a.s=2;
    if(s[1]==‘C‘)a.s=1;
}
bool Find(int u)
{
    for(int i=1; i<=n; i++)
    {
        if(!vis[i] && maps[u][i])
        {
            vis[i]=1;
            if(!used[i] || Find(used[i]))
            {
                used[i]=u;
                return true;
            }
        }
    }
    return false;
}
int main()
{
    int T;
    char s[11];
    scanf("%d", &T);
    while(T--)
    {
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        memset(maps, 0, sizeof(maps));
        memset(used, 0, sizeof(used));
        scanf("%d", &n);
        for(int i=1; i<=n; i++)
        {
            scanf("%s", s);
            change(s, a[i]);
        }
        for(int i=1; i<=n; i++)
        {
            scanf("%s", s);
            change(s, b[i]);
            for(int j=1; j<=n; j++)///建立b和a的关系,当为1时说明第二个人的那张牌大一第一个人的那张牌;
            {
                if(b[i].v>a[j].v)
                    maps[i][j] = 1;
                if(b[i].v==a[j].v && b[i].s>a[j].s)
                    maps[i][j] = 1;
            }
        }
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            memset(vis, 0, sizeof(vis));
            if(Find(i))
                ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}

时间: 2024-10-22 21:34:58

Card Game Cheater---hdu1528(二分匹配)的相关文章

Card Game Cheater(贪心+二分匹配)

Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1566    Accepted Submission(s): 822 Problem Description Adam and Eve play a card game using a regular deck of 52 cards. The rule

(hdu step 6.3.5)Card Game Cheater(匹配的最大数:a与b打牌,问b赢a多少次)

称号: Card Game Cheater Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 103 Accepted Submission(s): 74   Problem Description Adam and Eve play a card game using a regular deck of 52 cards. The rules

hdu----(1528)Card Game Cheater(最大匹配/贪心)

Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1272    Accepted Submission(s): 675 Problem Description Adam and Eve play a card game using a regular deck of 52 cards. The rule

HDOJ 1528 Card Game Cheater

简单二分图匹配.... Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1073    Accepted Submission(s): 565 Problem Description Adam and Eve play a card game using a regular deck of 52 ca

(hdu step 6.3.5)Card Game Cheater(最大匹配数:a与b打牌,问b能赢a多少次)

题目: Card Game Cheater Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 103 Accepted Submission(s): 74   Problem Description Adam and Eve play a card game using a regular deck of 52 cards. The rules

HDU 3861 The King’s Problem (强连通+二分匹配)

题目地址:HDU 3861 这题虽然是两个算法结合起来的.但是感觉挺没意思的..结合的一点也不自然,,硬生生的揉在了一块...(出题者不要喷我QAQ.) 不过这题让我发现了我的二分匹配已经好长时间没用过了..都快忘了..正好在省赛之前又复习了一下. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm>

hdu 4185 Oil Skimming(二分匹配)

Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 883    Accepted Submission(s): 374 Problem Description Thanks to a certain "green" resources company, there is a new profitable

【DFS求树的最大二分匹配+输入外挂】HDU 6178 Monkeys

http://acm.hdu.edu.cn/showproblem.php?pid=6178 [题意] 给定一棵有n个结点的树,现在有k个猴子分布在k个结点上,我们可以删去树上的一些边,使得k个猴子每个猴子都至少和其他一个猴子相连 问树上最少保留多少条边 [思路] 每个猴子要至少和一个猴子相连,考虑保留的边最少,那么最优的情况一定是一条边的两个顶点放两个猴子,这些边的顶点都不重合 我们现在要找到给定的树中最多有多少条这样的边,即最大二分匹配 O(n)的DFS,对于每个结点,优先与叶子结点形成一条

hdu 5093 Battle ships 最大二分匹配

Battle ships Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 589    Accepted Submission(s): 233 Problem Description Dear contestant, now you are an excellent navy commander, who is responsible