hdu-----(1507)Uncle Tom's Inherited Land*(二分匹配)
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
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). 
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.
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.
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
(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)
#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*(二分匹配)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- HDU 1507 Uncle Tom's Inherited Land(最大匹配+分奇偶部分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 题目大意:给你一张n*m大小的图,可以将白色正方形凑成1*2的长方形,问你最多可以凑出几块,并输 ...
- HDU 1507 Uncle Tom's Inherited Land*
题目大意:给你一个矩形,然后输入矩形里面池塘的坐标(不能放东西的地方),问可以放的地方中,最多可以放多少块1*2的长方形方块,并输出那些方块的位置. 题解:我们将所有未被覆盖的分为两种,即分为黑白格( ...
- hdu1507 Uncle Tom's Inherited Land* 二分匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 将i+j为奇数的构成x集合中 将i+j为偶数的构成y集合中 然后就是构建二部图 关键就是构图 然 ...
- 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 ...
- HDU1507 Uncle Tom's Inherited Land* 二分图匹配 匈牙利算法 黑白染色
原文链接http://www.cnblogs.com/zhouzhendong/p/8254062.html 题目传送门 - HDU1507 题意概括 有一个n*m的棋盘,有些点是废的. 现在让你用1 ...
- Uncle Tom's Inherited Land*
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
随机推荐
- jQuery模拟鼠标点击事件失效的问题
最近使用jQuery操作浏览器获取数据,需要对分页的信息进行处理,发现直接使用$('div#pager a.next').click();的这种写法无法触发点击事件. 使用trigger('click ...
- MySQL(六) —— 运算符和函数
1. 字符函数 函数名称 描述 CONCAT() 字符连接 CONCAT_WS() 使用指定的分隔符进行字 ...
- [SAP ABAP开发技术总结]选择屏幕——PARAMETERS
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- HTTP协议(转自:小坦克博客)
原文地址:http://www.cnblogs.com/TankXiao/archive/2012/02/13/2342672.html HTTP协议详解 当今web程序的开发技术真是百家争鸣,ASP ...
- FLASH CC 2015 CANVAS (六)如何像FLASH那样实现场景(多canvas)
注意 此系列贴 为个人边“开荒”边写,所以不保证就是最佳做法,也难免有错误! 正式教程会在后续开始更新. swf 项目中,我们可以很容易在一个fla文档里创建多场景.也可以通过多个fla文件发布多个s ...
- centos中更换jdk的版本
现在讲的是Linux中更换jdk版本的问题,卸载Linux自带的jdk更换sun的jdk百度一大堆,但是如果我安装的sun的jdk是1.7的想更换到1.8的如何解决呢,方法其实超easy. 把1.8的 ...
- TAROT.
/* * * */ #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int t ...
- 通过注解(annotation)配置Bean
Spring能够在classpath下自动扫描,侦测和实例化具有特定注解的组件,这在Spring中成为组件扫描(Component scanning). 特定组件的注解包括: @Component:基 ...
- wireshark使用教程
Wireshark: https://www.wireshark.org/ 安装: apt-get install wireshark 教程: http://blog.csdn.net/leichel ...
- Python循环嵌套
可以在循环体内嵌入其他的循环体,如在while循环中可以嵌入for循环, 反之,你可以在for循环中嵌入while循环. 实例: 以下实例使用了嵌套循环输出3~13之间的素数: 以上实例输出结果: F ...