题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=516

Your old uncle Tom inherited a piece of land from his great-great-uncle. Originally, the property had been in the shape of a rectangle. A long time ago, however, his great-great-uncle
decided to divide the land into a grid of small squares. He turned some of the squares into ponds, for he loved to hunt ducks and wanted to attract them to his property. (You cannot be sure, for you have not been to the place, but he may have made so many
ponds that the land may now consist of several disconnected islands.)



Your uncle Tom wants to sell the inherited land, but local rules now regulate property sales. Your uncle has been informed that, at his great-great-uncle's request, a law has been passed which establishes that property can only be sold in rectangular lots the
size of two squares of your uncle's property. Furthermore, ponds are not salable property.



Your uncle asked your help to determine the largest number of properties he could sell (the remaining squares will become recreational parks).

Input



Input will include several test cases. The first line of a test case contains two integers N and M, representing, respectively, the number of rows and columns of the land (1 <= N, M <= 100). The second line will contain an integer K indicating the number of
squares that have been turned into ponds ( (N x M) - K <= 50). Each of the next K lines contains two integers X and Y describing the position of a square which was turned into a pond (1 <= X <= N and 1 <= Y <= M). The end of input is indicated by N = M = 0.

Output



For each test case in the input your program should produce one line of output, containing an integer value representing the maximum number of properties which can be sold.

Sample Input

4 4

6

1 1

1 4

2 2

4 1

4 2

4 4

4 3

4

4 2

3 2

2 2

3 1

0 0

Sample Output

4

3


Source: South America 2002, Practice

题意:

有N * N 的土地,当中某些点被挖成池塘了,其余的地方为空地,

如今要分成 1 * 2 的空地来出售,

求最大能出售的数量。

PS:

把每块土地和他的上下左右建边!

代码例如以下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std; //顶点编号从1開始的
#define MAXN 117
int LN, RN;//L,R数目
int g[MAXN][MAXN], linker[MAXN];
bool used[MAXN];
int vis[MAXN][MAXN], a[MAXN][MAXN];
int dirx[4] = {0,0,1,-1};
int diry[4] = {1,-1,0,0};
int dfs(int L)//从左边開始找增广路径
{
int R;
for(R = 1; R <= RN; R++)
{
if(g[L][R]!=0 && !used[R])
{
//找增广路,反向
used[R]=true;
if(linker[R] == -1 || dfs(linker[R]))
{
linker[R]=L;
return 1;
}
}
}
return 0;
}
int hungary()
{
int res = 0 ;
int L;
memset(linker,-1,sizeof(linker));
for( L = 1; L <= LN; L++)
{
memset(used,0,sizeof(used));
if(dfs(L) != 0)
res++;
}
return res;
}
void init()
{
memset(a,0,sizeof(a));
memset(vis,0,sizeof(vis));
memset(g,0,sizeof(g));
}
int main()
{
int n, m;
int L, R;
int k;
while(~scanf("%d%d",&n,&m))
{
if(n==0 && m==0)
break;
init();
scanf("%d",&k);
int x, y;
int cont = 1;
for(int i = 1; i <= k; i++)
{
scanf("%d%d",&x,&y);
vis[x][y] = 1;//池塘
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(!vis[i][j])
{
a[i][j] = cont++;
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(!vis[i][j])
{
for(int h = 0; h < 4; h++)
{
int tx = i+dirx[h];
int ty = j+diry[h];
if(tx>=1&&tx<=n && ty>=1&&ty<=m && !vis[i][j])
{
g[a[i][j]][a[tx][ty]] = 1;
g[a[tx][ty]][a[i][j]] = 1;
}
}
}
}
}
LN = cont;
RN = cont;
int ans = hungary();
printf("%d\n",ans/2);
}
return 0 ;
}

ZOJ 1516 Uncle Tom&#39;s Inherited Land(二分匹配 最大匹配 匈牙利啊)的更多相关文章

  1. HDOJ 1507 Uncle Tom&#39;s Inherited Land*

    直接对每一个格子进行dfs结果除以2能够得到答案可是有大量反复的结果,不好输出答案. 能够仅仅对横纵坐标相加是奇数的格子dfs.... Uncle Tom's Inherited Land* Time ...

  2. hdu1507——Uncle Tom&#39;s Inherited Land*

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

  3. 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 ...

  4. ZOJ 1516 Uncle Tom's Inherited Land

    题目大意: 除去那些作为荷塘的土地块,将剩余的土地希望每次将两块相邻的地一起卖出,最多能卖出多少种这样的由相邻土地 合成的长方形土地块 很明显的二分图问题,但是要考虑如何建模 一个长方形土地总是由相邻 ...

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

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

  6. 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 ...

  7. ZOJ1516 Uncle Tom's Inherited Land(二分图最大匹配)

    一个经典的构图:对格子进行黑白染色,黑白的点分别作XY部的点. 这一题的边就是可以出售的单位面积2的土地,边的端点就是这个土地占用的X部和Y部的两个点. 这样就建好二分图,要求最多土地的答案显然是这个 ...

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

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

  9. 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 ...

随机推荐

  1. 大杂烩 Classpath / Build path / Debug关联源码 / JDK&JRE区别

    Classpath的理解及其使用方式 原文地址:http://blog.csdn.net/wk1134314305/article/details/77940147?from=bdhd_site 摘要 ...

  2. 微信小程序红包开发思路 微信红包小程序开发思路讲解

    之前公司开发小程序红包,将自己在开发的过程中遇到的一些坑分享到了博客里.不少人看了以后,还是不明白怎么开发.也加了我微信咨询.所以今天,我就特意再写一篇文章,这次就不谈我开发中遇到的坑了.就主要给大家 ...

  3. 使用UltraEdit 替换解决---文字中含有逗号的文件,如何把逗号自动转换成为:回车换行呢?

    实际工作中有时经常遇到一个问题: 一行文字中含有逗号,如何把逗号自动转换成为:回车换行呢? 普遍存在的问题,用Ultredit中^r^n(回车换行)也可以完成.提供大家参考. 王乐,李宏宇,张志鹏,刘 ...

  4. SharePoint 2013 App 开发—Auto Hosted 方式

    Auto Hosted 方式,自动使用Windows Azure来作为host,这种模式将App 发布到Office 365上的SharePoint Developer Site上.这种方式可以不用花 ...

  5. MySQL 5.7.17绿色版安装

    下载地址 :https://dev.mysql.com/downloads/mysql/   ,需要oracle帐号 下载  Windows (x86, 64-bit), ZIP Archive 是个 ...

  6. 【Eclpise】Eclipse中Tomcat启动失败或者是重启失败

    经常在Eclipse中遇到这样的问题,tomcat重启之后失败,而且也停止不了.最好的解决办法就是用DOS命令杀死进程. 比如下面这种情况: 1.查看进程ID  用windows的netstat查看信 ...

  7. luogu 1142 轰炸 最多共线点数

    题目链接 题意 给定\(n(n\leq 700)\)个点,问共线的点最多有多少个? 思路 \(O(n^3)\):枚举两个顶点确定一条直线,再看有多少个顶点在这条直线上.讲道理会T. \(O(n^2lo ...

  8. Git开发必知必会

    比如说你现在准备写一个自己的视频资源网站,在创业初期,你的项目暂时还是测试阶段,没有用户的时候,你可能只有一个人在开发,你每天都以写的内容和时间作为文件名的命名,这样其实是可以满足你对版本控制的基本需 ...

  9. SQL Server 内置函数实现MD5加密

    一.MD5加密 HASHBYTES ('加密方式', '待加密的值')     加密方式= MD2 | MD4 | MD5 | SHA | SHA1     返回值类型:varbinary(maxim ...

  10. cookies-判断用户是否是第一次进入页面

    在郑州美莱的活动项目中客户当时有提到该需求.尽管最后去掉了该需求,但是还是花了我不少时间研究,因为之前的项目我前端没有用到过cookies,吓死宝宝了 $(document).ready(functi ...