题目是跟 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. robotframework - create dictionary 操作

    1.创建字典 2.从字典中获取的项 -- 打印出 item 3.获取字典的key -- 打印出 key 4.获取字典的value -- 打印出 value 5.获取字典key,value 6.打印出字 ...

  2. CF379F New Year Tree

    题意翻译 你是一个程序猿,现在有一棵新年树(并不是传统的带着叶子的树)--它有四个节点: 1,2,3,4. 其中2,3,4的父亲都是1. 新年里,程序猿们往往会做一些有趣的事情.你则选择以往这棵树上加 ...

  3. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem

    Let SS be a sequence of integers s_{1}s​1​​, s_{2}s​2​​, ......, s_{n}s​n​​Each integer is is associ ...

  4. go 语言开发环境的安装与配置

    go 语言开发环境的安装与配置 编辑器选择 一直以来都是用sublime,但是听说sublime对于golang的插件支持并不是特别完善,并且VS Code只要在自身所带的扩展商店里安装go插件就可以 ...

  5. WebApi实现IHttpControllerSelector问题

    一.让Web API路由配置也支持命名空间参数/// <summary>    /// controller     /// 选择器    /// </summary>    ...

  6. CF868B Race Against Time

    思路: 模拟.少写了一个等号FST了,好气啊. 实现: #include <bits/stdc++.h> using namespace std; int main() { int h, ...

  7. JavaScript(第二部分)

    一.DOM获取元素节点的子节点  1.getElementsByTagName() 返回当前节点的指定标签名子节点 2.childNodes     表示当前节点的所有子节点 3.firstChild ...

  8. js中原型和原型链

    1.原型: 在JavaScript 中,对象被表现为prototype . 原型其实一直存在于我们接触过的任何一个对象. 2. Tip:在函数对象中也存在__proto__属性,但是查看函数对象的原型 ...

  9. ElasticSearch 安装使用

    安装: 1.下载ElasticSearch.解压到相关文件夹 2.运行elasticsearch.bat,启动程序 3.在浏览器输入:http://localhost:9200/,显示相关Es内容即安 ...

  10. LDA主题模型(理解篇)

    何谓“主题”呢?望文生义就知道是什么意思了,就是诸如一篇文章.一段话.一个句子所表达的中心思想.不过从统计模型的角度来说, 我们是用一个特定的词频分布来刻画主题的,并认为一篇文章.一段话.一个句子是从 ...