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

题意就是给有两个人有n张牌第二个人知道第一个人的牌的序列;

然后第二个人尽可能的让自己得更高的分,求这个最高分;

就是对方拿一张牌出来自己拿一张比他大的就得1分,如果相等就按红桃>黑桃>方块>梅花进行比较;

建图求最大匹配就可以了;注意:A是最大的牌。。。

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

Card Game Cheater---hdu1528(扑克建图求二分匹配)的更多相关文章

  1. We Need More Bosses CodeForces - 1000E(缩点 建图 求桥 求直径)

    题意: 就是求桥最多的一条路 解析: 先求连通分量的个数 然后缩点建图  求直径即可 #include <bits/stdc++.h> #define mem(a, b) memset(a ...

  2. Card Game Cheater HDU1528

    二分图最大匹配问题 扑克题还是用map比较方便 #include<bits/stdc++.h> using namespace std; #define MAXI 52 ]; ]; int ...

  3. Invitation Cards(邻接表+逆向建图+SPFA)

    Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 17538   Accepted: 5721 Description In ...

  4. HDU 4857 逃生 【拓扑排序+反向建图+优先队列】

    逃生 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...

  5. 【ARC069F】Flags 2-sat+线段树优化建图+二分

    Description ​ 数轴上有 n 个旗子,第 ii 个可以插在坐标 xi或者 yi,最大化两两旗子之间的最小距离. Input ​ 第一行一个整数 N. ​ 接下来 N 行每行两个整数 xi, ...

  6. kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树

    二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...

  7. HPU 3639--Hawk-and-Chicken【SCC缩点反向建图 &amp;&amp; 求传递的最大值】

    Hawk-and-Chicken Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. Codeforces Round #545 (Div. 2) E 强连通块 + dag上求最大路径 + 将状态看成点建图

    https://codeforces.com/contest/1138/problem/E 题意 有n个城市(1e5),有m条单向边(1e5),每一周有d天(50),对于每个城市假如在某一天为1表示这 ...

  9. Vulnerable Kerbals CodeForces - 772C【拓展欧几里得建图+DAG上求最长路】

    根据拓展欧几里得对于同余方程 $ax+by=c$ ,有解的条件是 $(a,b)|c$. 那么对于构造的序列的数,前一个数 $a$  和后一个数 $b$ ,应该满足 $a*x=b(mod m)$ 即 $ ...

随机推荐

  1. curl库 c语言的curl 编程

    c语言的curl 编程 [Linux@centos-64-min exercise]# gcc -Wall -o curltest curltest.c /tmp/ccosVANi.o: In fun ...

  2. P1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪

    呵呵呵呵呵,很水的DP,同时能够朴素枚举出来,这数据弱的 是 吃了尸米吧.. var n,i,j,k,l,ans:longint; begin readln(n); to trunc(sqrt(n)) ...

  3. Github for Windows使用图文教程

    原文:http://www.cr173.com/html/15618_1.html Git已经变得非常流行,连Codeplex现在也已经主推Git.Github上更是充斥着各种高质量的开源项目,比如r ...

  4. Leetcode-Construct Binary Tree from inorder and preorder travesal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...

  5. 查看linux命令类型

    type type -a type type是内建变量 root@akayer-p6:~# type -a lsls 是 `ls --color=auto' 的别名ls 是 /bin/ls

  6. 一些常用到的Centos命令

    CentOS常用命令在我们的使用中,经常被使用.所以,我们对一些经常使用又很重要的CentOS常用命令进行了全面的整理.下面,就来介绍这些CentOS常用命令. 一:使用CentOS常用命令查看cpu ...

  7. Ubuntu 16.04 下卸载 lnmp/lamp 方法

    1.卸载 apache2 sudo apt-get --purge remove apache2* sudo apt-get autoremove apache2 (--purge 是完全删除并且不保 ...

  8. Noip2008双栈排序

    [问题描述] 用两个栈使一个1...n的排列变得有序.一共有四个操作: A.stack1.push() 读入一个放入栈一 B.stack1.pop() 弹出栈一放入输出序列 C.stack2.push ...

  9. JSP页面批量选择&全选操作&选择回显

    效果如下: js验证部分: 页面body部分: 附:控制器Controller中验证批量选择条件回显:

  10. apple 官方文档 Push Notification Programming

    iOS Developer LibraryDeveloper Search Local and Push Notification Programming Guide PDF Table of Con ...