题目链接: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. sqlmap动态sql优化,避免传参失误批量修改和删除操作!

    分析以下的sqlmap存在问题: <delete id="deletePartspic" parameterClass="TblSpPartspic"&g ...

  2. iphone绘图的几个基本概念CGPoint、CGSize、CGRect、CGRectMake、window(窗口)、视图(view)

    我一般情况下不会使用interface builder去画界面,而是用纯代码去创建界面,不是装B,而是刚从vi转到xcode不久,不太习惯interface builder而已.当然如果需要我也会使用 ...

  3. codeforces #309 div1 A

    先说我的解法吧 首先设f(i,j)表示选了前i个球且j种颜色都已经选完了的方案数 这显然是可以随便转移的 #include<cstdio> #include<cstring> ...

  4. ios开发--网页中调用JS与JS注入

    先将网页弄到iOS项目中: 网页内容如下, 仅供测试: <html> <head> <meta xmlns="http://www.w3.org/1999/xh ...

  5. MSSQLServer基础01(数据类型)

    数据库设计:范式 现阶段,必须遵守满足3NF 1范式:列的原子性,即列不可再拆分 2范式:表中不能描述多个信息,不能有数据冗余 3范式:引用其它表的主键信息 数据类型的意义: 1>提高效率.(减 ...

  6. 218. The Skyline Problem

    题目: A city's skyline is the outer contour of the silhouette formed by all the buildings in that city ...

  7. Fundamental Datastructure

    11988 - Broken Keyboard (a.k.a. Beiju Text) 可以用deque来模拟. #include <iostream> #include <stri ...

  8. Android性能优化之如何避免Overdraw

    什么是Overdraw? Overdraw就是过度绘制,是指在一帧的时间内(16.67ms)像素被绘制了多次,理论上一个像素每次只绘制一次是最优的,但是由于重叠的布局导致一些像素会被多次绘制,而每次绘 ...

  9. Android 常用UI控件之TabHost(5)Tab栏在底部且在最上层也不盖tab页

    tab栏在底部 <TabHost android:id="@android:id/tabhost" android:layout_width="match_pare ...

  10. SQLServer与Oracle的数据同步(触发器trigger)

    说到同步,其实是靠"作业"定时调度存储过程来操作数据,增,删,改,全在里面,结合触发器,游标来实现,关于作业调度,使用了5秒运行一次来实行"秒级作业",这样基本 ...