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 ...
随机推荐
- Change An Item Property Using Set_Item_Property In Oracle Forms
Set_Item_Property is used to change an object's settings at run time. Note that in some cases you ca ...
- ImageMagick远程命令执行工具检测工具
ImageMagick这个漏洞昨天晚上就出来了,今天才有时间研究一下,今天自己也测试了一下 效果图: ======================= 用lua写了一个检测脚本 print (" ...
- python_way ,json(自学)
python_way ,json 如果我们想将多行字典存放到文件中,并且还需要调出这些字典继续使用那么就要是用json. 首先将字典用json转换成字符串,存放到文件中. a = {"tel ...
- Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心
C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 移动端图表插件jChart.js的修改
bug1: 折线图,设置datasetGesture : true时,Y轴的刻度值居然会变.会变也就算了,居然没地方设置不能变. bug2: 折线图,设置tap.point事件,和datasetGes ...
- java位运算符常见用法
1. 判断int型变量a是奇数还是偶数 a&1 = 0 偶数 a&1 = 1 奇数 2. 求平均值,比如有两个int类型变量x.y,首先要求x+y的和,再除以2,但是有可能x+y的结果 ...
- Android中向SD卡读写数据,读SD卡和手机内存
package com.example.sdoperation; import java.io.BufferedReader; import java.io.File; import java.io. ...
- Spring 框架的设计理念与设计模式分析
转载地址:https://www.ibm.com/developerworks/cn/java/j-lo-spring-principle/ Spring 作为现在最优秀的框架之一,已被广泛的使用,并 ...
- [转发] 理解 oauth 2.0
原文: http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html oauth 的各种编程语言实现: http://oauth.net/2/ 理解OAu ...
- Tomcat的使用
Tomcat的安装较为简单,尤其是Tomcat的安装文件apache-tomcat-7.0.19-windows-x86.zip,直接解压至目标目录下即可. Tomcat的安装目录下包括bin.con ...