题意:

在一幅扑克牌里,有两个人在比大小,第二个人最多能赢第一个人几张牌。

思路:

这道题目用一下二分匹配还是很明显的。

那么就是建图似乎要麻烦一下,但还是很方便的。将扑克牌一次进行编号,然后牌面比他小的就有一条边。这是一张大的图,两个人的手牌还是要标记一下,因为我们只对取到的牌操作。然后就是在这个范围内跑一跑二分匹配就好了。还是满基础的建图+二分匹配,我都1A了…

code:

#include<cstdio>
#include<math.h>
#include<vector>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 0X3f3f3f3f
typedef long long LL; int ma[55][55];
bool in1[55];
bool in2[55];
bool vis[55];
int cx[55];
int cy[55]; int findpath(int u)   //习惯写成findpath...
{
for(int i=1;i<=52;i++)
{
if(!vis[i]&&in2[i]&&ma[u][i])
{
vis[i]=1;
if(cy[i]==-1)
{
cx[u]=i;
cy[i]=u;
return 1;
}
else if(in1[cy[i]])
{
if(findpath(cy[i]))
{
cy[i]=u;
cx[u]=i;
return 1;
}
}
}
}
return 0;
} void init()
{
memset(ma,0,sizeof(ma));
for(int i=1;i<=52;i++)
{
for(int j=1;j<i;j++)
ma[i][j]=1;
}
} int get1(char x)
{
if(x>='2'&&x<='9')
return x-1-48;
if(x=='T')
return 9;
if(x=='J')
return 10;
if(x=='Q')
return 11;
if(x=='K')
return 12;
if(x=='A')
return 13;
}
int get2(char x)
{
if(x=='C')
return 1;
if(x=='D')
return 2;
if(x=='S')
return 3;
if(x=='H')
return 4;
} int main()
{
init();
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
char xx[3];
memset(in1,0,sizeof(in1));
memset(in2,0,sizeof(in2)); for(int i=0;i<n;i++)
{
scanf("%s",xx);
int s1=get1(xx[0]);
s1=(s1-1)*4;
int s2=get2(xx[1]);
in2[s1+s2]=1;
}
for(int i=0;i<n;i++)
{
scanf("%s",xx);
int s1=get1(xx[0]);
s1=(s1-1)*4;
int s2=get2(xx[1]);
in1[s1+s2]=1;
} // for(int i=1;i<=52;i++)
// {
// if(in2[i])
// printf("%d ",i);
// }
// puts("");
//
// for(int i=1;i<=52;i++)
// {
// if(in1[i])
// printf("%d ",i);
// }
// puts(""); memset(cx,-1,sizeof(cx));
memset(cy,-1,sizeof(cy)); int ans=0;
for(int i=1;i<=52;i++)
{
if(cx[i]==-1&&in1[i])
{
memset(vis,0,sizeof(vis));
if(findpath(i))
{
//printf("%d\n",i);
ans++;
}
}
}
printf("%d\n",ans);
}
return 0;
} /* 100
1
JD
JH
2
5D TC
4C 5H
3
2H 3H 4H
2D 3D 4D */

hdoj1528【二分匹配】的更多相关文章

  1. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  2. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  3. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  4. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  5. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  6. [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  7. [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)

    描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...

  8. nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...

  9. UVA5874 Social Holidaying 二分匹配

    二分匹配简单题,看懂题意,建图比较重要. #include<stdio.h> #include<string.h> #define maxn 1100 int map[maxn ...

随机推荐

  1. 关于android 使用bitmap的OOM心得和解决方式

    android开发,从2010年開始学习到如今的独立完毕一个app,这漫长的四年,已经经历了非常多次bug的折磨.无数次的加班训练.然而,自以为自己已经比較了解android了,却近期在一个项目上.由 ...

  2. 三联动 支持ie6,ie7 省,市,区

    三联动 支持ie6,ie7 省,市,区 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <tit ...

  3. 133. Clone Graph (3 solutions)——无向无环图复制

    Clone Graph Clone an undirected graph. Each node in the graph contains a label and a list of its nei ...

  4. Method Swizzling以及AOP编程:在运行时进行代码注入-b

    概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...

  5. C#3.0之神奇的Lambda表达式和Lambda语句

    “Lambda 表达式”是一个匿名函数,它可以包含表达式和语句,并且可用于创建委托或表达式目录树类型.所有 Lambda 表达式都使用 Lambda 运算符 =>,该运算符读为“goes to” ...

  6. android Graphics类:概述及基本几何图形绘制

    当须要在Android上绘制图形时.就会用到Graphics类.Paint类.Paint就是相当于笔,而Canvas就是 纸.这里叫画布. 所以,凡有跟要要画的东西的设置相关的.比方大小,粗细,画笔颜 ...

  7. Java堆内存与栈内存对比

    在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有什么异同,以及和数据结构中的堆栈有何关系? 一.Java 堆存储空间 堆内存(堆存储空间)会在Java运行时分配 ...

  8. LeetCode——Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  9. EnumChildWindows

    EnumChildWindows 函数功能:枚举一个父窗口的所有子窗口. 函数原型:BOOL EnumChildWindows(HWND hWndParent,WNDENUMPROC lpEnumFu ...

  10. LeetCode 112 Path Sum(路径和)(BT、DP)(*)

    翻译 给定一个二叉树root和一个和sum, 决定这个树是否存在一条从根到叶子的路径使得沿路全部节点的和等于给定的sum. 比如: 给定例如以下二叉树和sum=22. 5 / \ 4 8 / / \ ...