hdoj1528【二分匹配】
题意:
在一幅扑克牌里,有两个人在比大小,第二个人最多能赢第一个人几张牌。
思路:
这道题目用一下二分匹配还是很明显的。
那么就是建图似乎要麻烦一下,但还是很方便的。将扑克牌一次进行编号,然后牌面比他小的就有一条边。这是一张大的图,两个人的手牌还是要标记一下,因为我们只对取到的牌操作。然后就是在这个范围内跑一跑二分匹配就好了。还是满基础的建图+二分匹配,我都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【二分匹配】的更多相关文章
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- [kuangbin带你飞]专题十 匹配问题 二分匹配部分
刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...
- BZOJ 1189 二分匹配 || 最大流
1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1155 Solved: 420[Submi ...
- Kingdom of Obsession---hdu5943(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
- [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)
描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...
- nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...
- UVA5874 Social Holidaying 二分匹配
二分匹配简单题,看懂题意,建图比较重要. #include<stdio.h> #include<string.h> #define maxn 1100 int map[maxn ...
随机推荐
- MySQL的字符编码体系(一)——数据存储编码
安装MySQL好多次了,每次都会纠结于数据库的字符编码配置,所以我决定这一次彻底把它理清. MySQL的字符编码结构比較细,它慷慨向分为两个部分:数据存储编码和传输数据编码.本篇讨论数据存储编码部分, ...
- POJ - 3233 Matrix Power Series (矩阵等比二分求和)
Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + - + Ak. ...
- Raw-OS源代码分析之消息系统-Queue_Buffer
分析的内核版本号截止到2014-04-15,基于1.05正式版.blogs会及时跟进最新版本号的内核开发进度,若源代码凝视出现"???"字样,则是未深究理解部分. Raw-OS官方 ...
- CF 568A(Primes or Palindromes?-暴力推断)
A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- java开始到熟悉72-76
本次内容:异常机制 1.为什么需要异常 2.异常 3.error类 4.exception类 5.exception类中的unchecked exception 举例: 6.常用异常处理方法 a.tr ...
- redis中的五种基本的数据结构
1 String 基本的数据类型. 2 list 2.1 将元素放入一个list中 rpush mylist A rpush mylist B rpush mylist A 如果mylist本来是不存 ...
- De Moivre–Laplace theorem 掷硬币
De Moivre–Laplace theorem - Wikipedia https://en.wikipedia.org/wiki/De_Moivre%E2%80%93Laplace_theore ...
- C# 给窗体添加事件
1.https://zhidao.baidu.com/question/588485101.html
- Java经典算法大全
1.河内之塔.. 2.Algorithm Gossip: 费式数列. 3. 巴斯卡三角形 4.Algorithm Gossip: 三色棋 5.Algorithm Gossip: 老鼠走迷官(一) 6. ...
- vmware9虚拟机通过NAT上网方式设置
vmware虚机上网的网络连接方式有bridge.NAT.Host-only等,如果对这个不了解的可以学习这篇文章http://wangchunhai.blog.51cto.com/225186/38 ...