题目是跟 zoj1516是一样的,但多了匹配后的输出

详解zoj1516可见http://www.cnblogs.com/CSU3901130321/p/4228057.html

 #include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; const int maxn = ;
int n , m , k;
int g[maxn][maxn] , cx[maxn] , cy[maxn] , visy[maxn] , nx , ny;
bool col[][];//判断是否为鱼塘 struct Point{
int x , y;
Point(int x= , int y=):x(x),y(y){}
}; Point px[maxn] , py[maxn]; bool ok(Point p1 , Point p2)
{
if((p1.x == p2.x && abs(p1.y - p2.y) == ) || (p1.y == p2.y && abs(p1.x - p2.x) == ))
return true;
return false;
} void build_graph()
{
memset(g , , sizeof(g));
for(int i= ; i<=nx ; i++){
for(int j= ; j<=ny ; j++){
if(ok(px[i] , py[j]))
g[i][j] = ;
}
}
} int dfs(int u)
{
for(int v = ; v<=ny ; v++)
if(g[u][v] && !visy[v]){
visy[v] = ;
if(cy[v] == - || dfs(cy[v])){
cx[u] = v;
cy[v] = u;
return ;
}
}
return ;
} int MaxMatch()
{
memset(cx , - , sizeof(cx));
memset(cy , - , sizeof(cy));
int ans = ;
for(int i= ; i<=nx ; i++){
if(cx[i] == -){
memset(visy , , sizeof(visy));
ans += dfs(i);
}
}
return ans;
} int main()
{
// freopen("a.in" , "r" ,stdin);
while(scanf("%d%d" , &n , &m) , n)
{
scanf("%d" , &k);
int x , y;
memset(col , , sizeof(col));
while(k--){
scanf("%d%d" , &x , &y);
col[x][y] = ;
}
nx = , ny = ;
for(int i= ; i<=n ; i++)
for(int j= ; j<=m ; j++)
if(!col[i][j]){
if((i+j)&) py[++ny] = Point(i,j);
else px[++nx] = Point(i,j);
}
//构造二分图
build_graph();
printf("%d\n" , MaxMatch());
for(int i= ; i<=nx ; i++){
if(cx[i] != -)
printf("(%d,%d)--(%d,%d)\n",px[i].x , px[i].y , py[cx[i]].x , py[cx[i]].y);
}
}
return ;
}

HDU1507 Uncle Tom's Inherited Land*的更多相关文章

  1. hdu-----(1507)Uncle Tom's Inherited Land*(二分匹配)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. HDU1507 Uncle Tom's Inherited Land* 二分图匹配 匈牙利算法 黑白染色

    原文链接http://www.cnblogs.com/zhouzhendong/p/8254062.html 题目传送门 - HDU1507 题意概括 有一个n*m的棋盘,有些点是废的. 现在让你用1 ...

  3. hdu1507 Uncle Tom's Inherited Land* 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 将i+j为奇数的构成x集合中 将i+j为偶数的构成y集合中 然后就是构建二部图 关键就是构图 然 ...

  4. HDU 1507 Uncle Tom's Inherited Land*(二分图匹配)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  5. Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  6. Uncle Tom's Inherited Land*

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...

  7. HDU 1507 Uncle Tom's Inherited Land*(二分匹配,输出任意一组解)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  8. XTU 二分图和网络流 练习题 B. Uncle Tom's Inherited Land*

    B. Uncle Tom's Inherited Land* Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I ...

  9. HDU——T 1507 Uncle Tom's Inherited Land*

    http://acm.hdu.edu.cn/showproblem.php?pid=1507 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

随机推荐

  1. P4244 [SHOI2008]仙人掌图 II

    传送门 仙人掌直径,以前好像模拟赛的时候做到过一道基环树的直径,打了个很麻烦的然而还错了--今天才发现那就是这个的弱化版啊-- 如果是树的话用普通的dp即可,记\(f[u]\)表示\(u\)往下最长能 ...

  2. Vue学习-Element框架

    今天学了一个基于Vue2.0的桌面端组件库Element,号称是全世界最流行的Vue UI框架.感觉学会了之后就变身大牛了有木有. 好了,不吹牛皮了. Element官方文档通俗易懂,框架什么的安装引 ...

  3. javascript实现引用数据类型的深拷贝和浅拷贝详解

    关于引用类型值的详解,请看另一篇随笔 https://www.cnblogs.com/jinbang/p/10346584.html 深拷贝和浅拷贝,也就是引用数据类型栈和堆的知识点.深浅拷贝的原型都 ...

  4. java 序列化和反序列化数据

    使用ObjectOutputStream 序列号原始数据和对象数据,使用ObjectInputStream 反序列化 使用字节存储数据,可以将序列化的数据存储到硬盘上,或输出到网络上 package ...

  5. 推荐一波 瀑布流的RecylceView

    推荐博客:http://www.bubuko.com/infodetail-999014.html

  6. 转 linux之sed命令详解

    http://jingyan.baidu.com/article/fec4bce2228f60f2618d8bb0.html sed  编辑裁剪文件命令 sed -i "s/\/db\/te ...

  7. [转]ASP.NET MVC的帮助类HtmlHelper和UrlHelper

    本文转自:http://www.cnblogs.com/greatandforever/archive/2010/04/20/1715914.html?login=1 在ASP.NET MVC框架中没 ...

  8. SQL在一张表中根据父ID获取所有的子ID

    with a as ( select id,name,parentid from categories where id=53 union all select x.id,x.name,x.paren ...

  9. Kerberos 简介——教你做个好人

    文章导读: 对称加密 非对称加密 数字证书 Kerberos认证流程 Hadoop生态利用Kerberos认证机制来识别可靠的服务和节点,保障Hadoop集群的安全,那么Kerberos到底是什么?为 ...

  10. Elasticsearch--更好的搜索_加权得分,脚本,同义词

    目录 Apache Lucene评分 Elasticsearch的脚本功能 脚本执行过程中可以使用的对象 使用自定义的脚本库 搜索不同语言的内容 使用加权影响得分 加权 function_score查 ...