题意:

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

思路:

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

那么就是建图似乎要麻烦一下,但还是很方便的。将扑克牌一次进行编号,然后牌面比他小的就有一条边。这是一张大的图,两个人的手牌还是要标记一下,因为我们只对取到的牌操作。然后就是在这个范围内跑一跑二分匹配就好了。还是满基础的建图+二分匹配,我都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. lua 异常 错误处理 pcall

    lua 错误处理 匿名函数 if pcall(function () local s=object.data[1]['type'] end) then return object.data[1]['t ...

  2. POJ3067:Japan(线段树)

    Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for th ...

  3. Ubuntu搭建Android开发环境

    前言 由于迁移到新的笔记本,所以Android开发环境须要又一次配置了.android官网有配置教程,我正好回想一遍 配置Java环境 下载jdk.官网地址:http://www.oracle.com ...

  4. 第一个MapReduce程序——WordCount

    通常我们在学习一门语言的时候,写的第一个程序就是Hello World.而在学习Hadoop时,我们要写的第一个程序就是词频统计WordCount程序. 一.MapReduce简介 1.1 MapRe ...

  5. CF 568A(Primes or Palindromes?-暴力推断)

    A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...

  6. SPOJ VLATTICE Visible Lattice Points (莫比乌斯反演基础题)

    Visible Lattice Points Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at ...

  7. 获取Wifi密码,不知道是不是真的

    package com.example.wifipassword; import java.util.List; import android.app.Activity; import android ...

  8. node.js内存泄露问题记录

    先说一下.事情的来龙去脉. 公司开发一款游戏棋牌游戏,服务端的开发是IO密集型,开发的时候,考虑过使用python,java,node.js. 终于选择了node.js(node.js宣传的杀手功能. ...

  9. 2016/06/16 phpexcel

      程序部分   require_once './phpexcel/PHPExcel.php';   // 首先创建一个新的对象  PHPExcel object $objPHPExcel = new ...

  10. BZOJ 3992: [SDOI2015]序列统计 快速幂+NTT(离散对数下)

    3992: [SDOI2015]序列统计 Description 小C有一个集合S,里面的元素都是小于M的非负整数.他用程序编写了一个数列生成器,可以生成一个长度为N的数列,数列中的每个数都属于集合S ...