题意:有水平N张牌,竖直M张牌,同一方向的牌不会相交。水平的和垂直的可能会相交,求最少踢出去几张牌使剩下的牌都不相交。

二分匹配 最小点覆盖=最大匹配。

链接:点我

坐标点作为匹配的端点

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
int n,m,tt;
/*
* 匈牙利算法邻接表形式
* 使用前用init()进行初始化,给uN赋值
* 加边使用函数addedge(u,v)
*
*/
const int MAXN = ;//点数的最大值
const int MAXM = ;//边数的最大值
struct Edge
{
int to,next;
}edge[MAXM];
int head[MAXN],tot;
void init()
{
tot = ;
memset(head,-,sizeof(head));
}
void addedge(int u,int v)
{
edge[tot].to = v; edge[tot].next = head[u];
head[u] = tot++;
}
int linker[MAXN];
bool used[MAXN];
int uN;
bool dfs(int u)
{
for(int i = head[u]; i != - ;i = edge[i].next)
{
int v = edge[i].to;
if(!used[v])
{
used[v] = true;
if(linker[v] == - || dfs(linker[v]))
{
linker[v] = u;
return true;
}
}
}
return false;
}
int hungary()
{
int res = ;
memset(linker,-,sizeof(linker));
for(int u = ; u < uN;u++)//点的编号0~uN-1
{
memset(used,false,sizeof(used));
if(dfs(u))res++;
}
return res;
}
pair<int,int> p1[MAXN];
pair<int,int> p2[MAXN];
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==) break;
init();
int x,y;
for(i=;i<n;i++)
{
scanf("%d%d",&x,&y);
p1[i]=make_pair(x,y);
}
for(i=;i<m;i++)
{
scanf("%d%d",&x,&y);
p2[i]=make_pair(x,y);
}
uN=n;
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
int x1=p1[i].first;
int y1=p1[i].second;
int x2=p2[j].first;
int y2=p2[j].second;
if((x1==x2&&y1==y2)||(x1+==x2&&y1==y2)||(x1==x2&&y1==y2+)||(x1+==x2&&y1==y2+))
{
addedge(i,j);
}
}
}
printf("%d\n",n+m-hungary());
}
}

hdu 4169 二分匹配最大独立集 ***的更多相关文章

  1. HDU - 1068 Girls and Boys(二分匹配---最大独立集)

    题意:给出每个学生的标号及与其有缘分成为情侣的人的标号,求一个最大集合,集合中任意两个人都没有缘分成为情侣. 分析: 1.若两人有缘分,则可以连一条边,本题是求一个最大集合,集合中任意两点都不相连,即 ...

  2. hdu 5093 二分匹配

    /* 题意:给你一些冰岛.公共海域和浮冰,冰岛可以隔开两个公共海域,浮冰无影响 求选尽可能多的选一些公共海域点每行每列仅能选一个. 限制条件:冰山可以隔开这个限制条件.即*#*可以选两个 预处理: * ...

  3. Battle ships HDU - 5093二分匹配

    Battle shipsHDU - 5093 题目大意:n*m的地图,*代表海洋,#代表冰山,o代表浮冰,海洋上可以放置船舰,但是每一行每一列只能有一个船舰(类似象棋的車),除非同行或者同列的船舰中间 ...

  4. hdu 4685 二分匹配+强连通分量

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4685 题解: 这一题是poj 1904的加强版,poj 1904王子和公主的人数是一样多的,并且给出 ...

  5. hdu3829 二分匹配 最大独立集

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Problem ...

  6. H - Prince and Princess - HDU 4685(二分匹配+强连通分量)

    题意:有N个王子M个公主,王子喜欢一些公主,而且只能是王子喜欢的人,他们才可以结婚,现在让他们尽可能多的结婚的前提下找出来每个王子都可以和谁结婚. 分析:先求出来他们的最大匹配,因为给的数据未必是完备 ...

  7. HDU 3729 二分匹配 反向匹配

    题意: 给定 n个学生 说的 自己 考试排名的 可能范围 确定最多几个人说真话 如果有多种答案,输出字典序最大的那种( 要求字典序最大,所以solve中从最大字典序开始匹配) 思路: 题目给定  点 ...

  8. Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集

    m种阳离子 n种阴离子 然后一个m*n的矩阵 第i行第j列为1代表第i种阴离子和第j种阴离子相互吸引 0表示排斥 求在阳离子和阴离子都至少有一种的情况下 最多存在多少种离子能够共存 阴阳离子都至少须要 ...

  9. HDU -1151 二分匹配与有向无环图不相交最小路径覆盖数

    题意: 考虑一个小镇,那里的所有街道都是单向的,并且每条街道都从一个路口通往另一个路口.还众所周知,从一个十字路口开始,穿过城镇的街道,您将永远无法到达同一十字路口,即,城镇的街道没有环. 基于这些假 ...

随机推荐

  1. 【1】ConcurrentModificationException 异常解析和快速失败,安全失败

    目录 一.引起异常的代码 二.foreach原理 三.从ArrayList源码找原因 四.单线程解决方案 五.在多线程环境下的解决方法 一.引起异常的代码 以下三种的遍历集合对象时候,执行集合的rem ...

  2. Does Deep Learning Come from the Devil?

    Does Deep Learning Come from the Devil? Deep learning has revolutionized computer vision and natural ...

  3. 思考的乐趣----matrix67数学笔记:最精妙的无字证明

    从<思考的乐趣----matrix67数学笔记>一书中看到这个证明,据说在mathoverflow网站上这个无字证明获得了最多的投票! http://mathoverflow.net/qu ...

  4. H5 Day2 练习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. CF 1131B Draw!

    Draw! Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Descriptio ...

  6. 第9月第7天 uicollectionview

    1. /** The margins used to lay out content in the section controller. @see `-[UICollectionViewFlowLa ...

  7. CUDA性能优化----warp深度解析

    本文转自:http://blog.163.com/wujiaxing009@126/blog/static/71988399201701224540201/ 1.引言 CUDA性能优化----sp, ...

  8. Strange Queries(莫队)

    题目 You are given an array with n integers a1, a2, ..., an, and q queries to answer. Each query consi ...

  9. rstful登陆认证并检查session是否过期

    一:restful用户视图 #!/usr/bin/env python # -*- coding:UTF-8 -*- # Author:Leslie-x from users import model ...

  10. 20155303 实验三 敏捷开发与XP实践

    20155303 实验三 敏捷开发与XP实践 目录 一.编码标准 任务一:在IDEA中使用工具(Code->Reformate Code)格式化代码,并学习Code菜单的功能 二.敏捷开发与XP ...