题目是跟 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. [Usaco2013 Nov]No Change

    Description Farmer John is at the market to purchase supplies for his farm. He has in his pocket K c ...

  2. pyinstaller打包报错:AttributeError: 'str' object has no attribute 'items'

    导致原因和python多数奇奇怪怪的问题一样,依赖包的版本问题. 解决办法: 对setuptools这个包进行升级,链接在这里 https://pypi.org/project/setuptools/ ...

  3. LN : leetcode 399 Evaluate Division

    lc 399 Evaluate Division 399 Evaluate Division Equations are given in the format A / B = k, where A ...

  4. scala-基础-映射(1)

    //映射(1)-构建,获取,更新,迭代,反转,映射(可变与不可变 互换) class Demo1 extends TestCase { //构建与获取 def test_create_^^(){ // ...

  5. [ NOI 2001 ] 方程的解数

    \(\\\) \(Description\) 已知一个 \(N\) 元高次方程: \[ k_1x_1^{p_1}+k_2x_2^{p_2}+...+k_nx_n^{p_n}=0 \] 要求所有的 \( ...

  6. CF817A Treasure Hunt

    思路: 起点(x1, y1),终点(x2, y2),步长(dx, -dy),(dx, dy),(-dx, -dy),(-dx, dy).只要满足abs(x1 - x2) % dx == 0 并且 ab ...

  7. ADPU 大全

    APDU协议 APDU协议,即是智能卡与读写器间的应用层协议,在ISO7816-4[7]中定义了该协议的结构格式.APDU数据有两种结构,读写器使用的APDU结构为命令APDU,C-APDU(Comm ...

  8. JNDI链接SQLServer数据库步骤

    1.配置context.xml文件 在我们的WebRoot目录下,就是和WEB-INF同级的目录下,新建一个META-INF的目录(假如不存在),在该目录下创建一个context.xml文件,并且在c ...

  9. Windows sever 2003 IIS6.0 搭建DVWA

    DVWA 环境: Windows Sever 2003 IIS 6.0+MYSQL+PHP5.4+FASFCGI 详细教程: http://files.cnblogs.com/files/yyx001 ...

  10. Masonry 原理与使用说明

    原理: 1)约束生成:MASConstraintMaker: 2)缺省补齐: - (void)setSecondViewAttribute:(id)secondViewAttribute { if ( ...