Uncle Tom's Inherited Land*

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2013    Accepted Submission(s): 830
Special Judge

Problem Description
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 first output one line,
containing an integer p representing the maximum number of properties
which can be sold. The next p lines specify each pair of squares which
can be sold simultaneity. If there are more than one solution, anyone is
acceptable. there is a blank line after each test case. See sample
below for clarification of the output format.
 
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
(1,2)--(1,3)
(2,1)--(3,1)
(2,3)--(3,3)
(2,4)--(3,4)

3
(1,1)--(2,1)
(1,2)--(1,3)
(2,3)--(3,3)

 
Source
 
这道题,怎么说呢,比较的抽象,就是将一个点作为一个匹配的对象来处理,比较容易想到最大匹配,至于这个点的坐标该如何来存放
可以开四维的数组,貌似这样会到10e8+的数据规模 达到250M的样子,所以放弃这个念头...转而用结构体来定义自己的变量
然后就是一个一如既往的匈牙利算法啦,但是在遍历所有的坐标时,虽然可以求出正确的匹配数,貌似在输出那个谁匹配谁的时候,又不好处理
比如  你在 (1,2)这个点的时候,假如你和(1,3)匹配了,那么在(1,3)那个点时,又会有(1,3)匹配(1,2)这样就不好处里了...
于是呼,你会发现这个地方的匹配有些奇特,那就是貌似他临近的点的坐标的和总和所在点呈现奇偶互异的状态,所以我们不妨这样搞,取这个点就不在取那个点
就这样跳跃着,取点,然后就可以了....这样的话,一切就都ok了....
代码:
 #include<cstring>
#include<cstdio>
#include<cstdlib>
#define init(a) memset(a,0,sizeof(a))
const int maxn=;
bool map[maxn][maxn];
bool vis[maxn][maxn];
struct node{
int x,y;
};
node mat[maxn][maxn];
int n,m;
int dir[][]={{,},{,-},{,},{-,}};
int match(node aa){ node tem;
if(!map[aa.x][aa.y]){
for(int ll=;ll<;ll++) //扫描它的四周...
{
tem=(node){aa.x+dir[ll][],aa.y+dir[ll][]};
if(tem.y>&&tem.x>&&tem.x<=n&&tem.y<=m&&!map[tem.x][tem.y]&&!vis[tem.x][tem.y]){
vis[tem.x][tem.y]=;
if(!mat[tem.x][tem.y].x||match(mat[tem.x][tem.y])){
mat[tem.x][tem.y]=aa;
return ;
}
}
}
}
return ;
}
int main()
{
int k,x,y;
//freopen("test.in","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF,n+m){
scanf("%d",&k);
init(map);
while(k--){
scanf("%d%d",&x,&y);
map[x][y]=; //代表一个池塘
}
init(mat);
int ans=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(((i+j)&)){ //不娶相邻的点...取奇数或者偶数都一样,,
init(vis);
ans+=match((node){i,j});
}
}
}
printf("%d\n",ans);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(mat[i][j].x){
printf("(%d,%d)--(%d,%d)\n",i,j,mat[i][j].x,mat[i][j].y);
}
}
}
}
return ;
}

hdu-----(1507)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. 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 ...

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

  4. HDU 1507 Uncle Tom's Inherited Land(最大匹配+分奇偶部分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 题目大意:给你一张n*m大小的图,可以将白色正方形凑成1*2的长方形,问你最多可以凑出几块,并输 ...

  5. HDU 1507 Uncle Tom's Inherited Land*

    题目大意:给你一个矩形,然后输入矩形里面池塘的坐标(不能放东西的地方),问可以放的地方中,最多可以放多少块1*2的长方形方块,并输出那些方块的位置. 题解:我们将所有未被覆盖的分为两种,即分为黑白格( ...

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

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

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

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

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

  9. Uncle Tom's Inherited Land*

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

随机推荐

  1. C#日志写入

    /// <summary> /// 写日志,指定日志文件 /// </summary> /// <param name="File"></ ...

  2. Web开发, 跳转时出现java.lang.ClassNotFoundException

    发生这种状况一般都是由于类找不到,要么是web.xml没有配对位置,要么是类没有放好

  3. 获取Token不完整问题

    有时会遇到获取Token只能获取一半的问题,明明有两个Cookie,但只获取到一个,这个是因为301重定向跳转设置问题,设置为True就可以获取到完整的Token了. myHttpWebRequest ...

  4. Python基础学习笔记(十一)函数、模块与包

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-functions.html 3. http://www.liao ...

  5. 解决使用jQuery采用append添加的元素事件无效的方法

    <html> <head> <script type="text/javascript" src="/jquery/jquery.js&qu ...

  6. js操作cookie,实现登录密码保存 [转]

    转自:http://blog.csdn.net/zyujie/article/details/8727828 ( 谢谢博主了) js操作cookie,实现登录密码保存.cookie的存放方式是以键值对 ...

  7. Spring管理bean的生命周期

    1: bean的创建:   如果我们默认的scope配置为Singleton的话, bean的创建实在Spring容器创建的时候创建: 如果scope的配置为Prototype的话,bena的创建是在 ...

  8. list map vector set 常用函数列表

    #include <stdio.h> #include <iostream>//cin,cout #include <sstream>//ss transfer. ...

  9. sql for xml 嵌套

    找很久.原来差一个ELEMENTS 关键字. 想到哪里插入子节点.就直接写一条语句,加一个ELEMENTS. 为什么baidu这么就都找不到.到处都是转来转去的东西.郁闷. select h.*,(s ...

  10. 2014 Multi-University Training Contest 4

    1006 hdu4902 #include <iostream> #include<stdio.h> #include<vector> #include<qu ...