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

  一看就知道是二分匹配题目,对每个点拆点建立二分图,最后答案除2。因为这里是稀疏图,用邻接表处理。。。

 //STATUS:C++_AC_31MS_480KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int n,m;
int vis[N*],id[N][N],y[N*];
int tot; struct Edge{
int u,v;
}e[];
int first[N*],next[];
int mt; void adde(int a,int b) //对于一条边,需建立双向边,一个容量为cap,反向边容量为0!
{
e[mt].u=a;e[mt].v=b;
next[mt]=first[a];first[a]=mt++;
e[mt].u=b;e[mt].v=a;
next[mt]=first[b];first[b]=mt++;
} int dfs(int u)
{
int i;
for(i=first[u];i!=-;i=next[i]){
if(!vis[e[i].v]){
vis[e[i].v]=;
if(!y[e[i].v] || dfs(y[e[i].v])){
y[e[i].v]=u;
return ;
}
}
}
return ;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,a,b,ans;
while(~scanf("%d%d",&n,&m) && (n || m))
{
mem(id,);
tot=;mt=;mem(first,-);
for(i=;i<n;i++){
scanf("%d%d",&a,&b);
if(!id[a][b])id[a][b]=tot++;
if(!id[a+][b])id[a+][b]=tot++;
adde(id[a][b],id[a+][b]);
}
for(i=;i<m;i++){
scanf("%d%d",&a,&b);
if(!id[a][b])id[a][b]=tot++;
if(!id[a][b+])id[a][b+]=tot++;
adde(id[a][b],id[a][b+]);
} ans=;
mem(y,);
for(i=;i<tot;i++){
mem(vis,);
if(dfs(i))ans++;
} printf("%d\n",ans>>);
}
return ;
}

HDU-4619 Warm up 2 二分匹配的更多相关文章

  1. hdu 4619 Warm up 2 (二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 题意: 平面上有一些1×2的骨牌,每张骨牌要么水平放置,要么竖直放置,并且保证同方向放置的骨牌不 ...

  2. hdu 4619 Warm up 2 二分图匹配

    题目链接 给两种长方形, 水平的和垂直的, 大小都为1*2, n个水平的, m个垂直的, 给出它们的坐标. 水平的和垂直的可以相互覆盖, 但是同种类型的没有覆盖. 去掉一些长方形, 使得剩下的全部都没 ...

  3. HDU 4619 Warm up 2(2013多校2 1009 二分匹配)

    Warm up 2 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total S ...

  4. HDU 2063 过山车(二分匹配入门)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...

  5. HDU - 1045 Fire Net(二分匹配)

    Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...

  6. hdu 4619 Warm up 2 网络流 最小割

    题意:告诉你一些骨牌,然后骨牌的位置与横竖,这样求最多保留多少无覆盖的方格. 这样的话有人用二分匹配,因为两个必定去掉一个,我用的是最小割,因为保证横着和竖着不连通即可. #include <s ...

  7. hdu 4619 Warm up 2(并查集)

    借用题解上的话,就是乱搞题.. 题意理解错了,其实是坐标系画错了,人家个坐标系,我给当矩阵画,真好反了.对于题目描述和数据不符的问题,果断相信数据了(这是有前车之鉴的hdu 4612 Warm up, ...

  8. HDU 2063 过山车 二分匹配

    解题报告:有m个女生和n个男生要结成伴坐过山车,每个女生都有几个自己想选择的男生,然后要你确定最多能组成多少对组合. 最裸的一个二分匹配,这是我第一次写二分匹配,给我最大的感受就是看那些人讲的匈牙利算 ...

  9. hdu 1528 Card Game Cheater (二分匹配)

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

随机推荐

  1. Maven for Myeclipse的一个常见错误 Project configuration is not up-to-date with pom.xml

    使用Myeclipse开发Maven项目时,经常会发现一个错误提示: Description Resource Path Location Type Project configuration is ...

  2. 组策略限制添加用户作为服务登录导致ITAtomcat服务无法启动(log on as a service)

    [故障类型]:ITA tomcat服务器无法启动. [关 键 词]:Logon as a service  作为服务登录  tomcat  loggeter [适用版本]:FusionCloud So ...

  3. [译]15个关于Chrome的开发必备小技巧

    谷歌Chrome,是当前最流行且被众多web开发人员使用的浏览器.最快六周就更新发布一次以及伴随着它不断强大的开发组件,使得Chrome成为你必备的开发工具.例如,在线编辑CSS,console以及d ...

  4. cmd启动tomcat

    1.安装jdk 2.安装tomcat 3.需要配置两个用户环境变量,仅仅配置系统变量没用. a)JAVA_HOME:D:\programing~tools\java~tools\JDK(tm)\jdk ...

  5. caffe简易上手指南(一)—— 运行cifar例子

    简介 caffe是一个友好.易于上手的开源深度学习平台,主要用于图像的相关处理,可以支持CNN等多种深度学习网络. 基于caffe,开发者可以方便快速地开发简单的学习网络,用于分类.定位等任务,也可以 ...

  6. 【开源推荐】AllJoyn:打造全球物联网的通用开源框架

    摘要:随着智能设备的发展,物联网逐渐进入了人们的生活.据预测,未来几乎一切东西(超过500亿台设备)都可以互联.高通公司发布了开源项目AllJoyn,这是一个能够使连接设备间进行互操作的通用软件框架和 ...

  7. Area of a Circle

    Area of a Circle Description: Complete the function circleArea so that it will return the area of a ...

  8. 基于邻接矩阵的广度优先搜索遍历(BFS)

    题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2141&cid=1186 #include<stdio.h> #incl ...

  9. SGU185 - Two Shortest

    原题地址:http://acm.sgu.ru/problem.php?contest=0&problem=185 题目大意:给出一个无向图,求出从 1 到 n 的两条没有相同边的最短路径(允许 ...

  10. hud 3336 count the string (KMP)

    这道题本来想对了,可是因为hdu对pascal语言的限制是我认为自己想错了,结果一看题解发现自己对了…… 题意:给以字符串 计算出以前i个字符为前缀的字符中 在主串中出现的次数和 如: num(aba ...