Uncle Tom's Inherited Land*

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1869    Accepted Submission(s): 777

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)

题意就是找出最多的1*2的方块来,UP主的主要思路为:以i+j的奇偶性为分类,因为每个1*2的方块肯定是由一个奇点和一个偶点构成,二分图是思路都是某个东西由2类东西构成,再去用匈牙利算法,然后再用map数组偶点存匹配的方向

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int map[105][105];
bool vis[105][105];
int d[5][2]={{0,0},{1,0},{0,1},{-1,0},{0,-1}};
int x, y;
void myscanf()
{
memset(map,0,sizeof(map));
int m, a, b;
scanf("%d",&m);
while(m--)
{
scanf("%d%d",&a,&b);
map[a][b] = -1;
}
} void myprintf(int xi, int yi)
{
int f = map[xi][yi];
int fx = d[f][0] + xi;
int fy = d[f][1] + yi;
printf("(%d,%d)--(%d,%d)\n",xi,yi,fx,fy);
} bool pd(int xi, int yi)
{
if(xi<=0 || xi>x || yi<=0 || yi>y || map[xi][yi]==-1) return false;
return true;
} bool dfs(int xi,int yi)
{
for(int i=1;i<=4;i++)
{
int fx = xi+d[i][0];
int fy = yi+d[i][1];
if(pd(fx,fy) && !vis[fx][fy])
{
vis[fx][fy] = true;
int f = map[fx][fy];
int ex = fx + d[f][0];
int ey = fy + d[f][1];
if(!f || dfs(ex,ey))
{
map[fx][fy] = (i+2)%4==0?4:(i+2)%4;
return true;
}
}
}
return false;
} int find()
{
int res = 0;
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
if((i+j)%2)
{
memset(vis,0,sizeof(vis));
if(map[i][j]==-1) continue;
if(dfs(i,j)) res++;
}
}
}
return res;
} int main()
{
// freopen("in.txt","r+",stdin);
// freopen("out1.txt","w+",stdout);
while(scanf("%d%d",&x,&y)!=EOF)
{
if(x==0 && y==0) break;
myscanf();
cout<<find()<<endl;
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
if(map[i][j]>0)
{
myprintf(i,j);
}
}
}
printf("\n");
}
// fclose(stdin);
// fclose(stdout);
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏的更多相关文章

  1. 修改MS SQL忽略大小写 分类: SQL Server 数据库 2015-06-19 09:18 34人阅读 评论(0) 收藏

    第一步:数据库->属性->选项->限制访问:SINGLE_USER 第二步:ALTER DATABASE [数据库名称] collate Chinese_PRC_CI_AI 第三步: ...

  2. *** glibc detected *** malloc(): memory corruption 分类: C/C++ Linux 2015-05-14 09:22 37人阅读 评论(0) 收藏

    *** glibc detected *** malloc(): memory corruption: 0x09eab988 *** 发现是由于memset越界写引起的. 在Linux Server上 ...

  3. 哈希-4 Values whose Sum is 0 分类: POJ 哈希 2015-08-07 09:51 3人阅读 评论(0) 收藏

    4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 17875 Accepted: ...

  4. 哈希-Gold Balanced Lineup 分类: POJ 哈希 2015-08-07 09:04 2人阅读 评论(0) 收藏

    Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13215 Accepted: 3873 ...

  5. nginx 安装手记 分类: Nginx 服务器搭建 2015-07-14 14:28 15人阅读 评论(0) 收藏

    Nginx需要依赖下面3个包 gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ ) zlib-1.2.8.tar.gz rewrite 模块需要 pcre 库 ( ...

  6. 快速查询本机IP 分类: windows常用小技巧 2014-04-15 09:28 138人阅读 评论(0) 收藏

    第一步: 点击windows建(屏幕左下方),在搜索程序和文件文本框内输入:cmd 第二步:      点击Enter建进入. 第三步: 输入:ipconfig即可. 版权声明:本文为博主原创文章,未 ...

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

  9. sscanf 函数 分类: POJ 2015-08-04 09:19 4人阅读 评论(0) 收藏

    sscanf 其实很强大 分类: 纯C技术 技术笔记 2010-03-05 16:00 12133人阅读 评论(4) 收藏 举报 正则表达式stringbuffercurlgoogle 最近在做日志分 ...

随机推荐

  1. MongoDB 插入文档

    文档的数据结构和JSON基本一样. 所有存储在集合中的数据都是BSON格式. BSON是一种类json的一种二进制形式的存储格式,简称Binary JSON. 插入文档 MongoDB 使用 inse ...

  2. Azkaban 作业调度

    转载一篇不错的文章:http://www.cnblogs.com/smartloli/p/5191155.html

  3. 【原创】解决鼠标经过子元素触发mouseout,mouseover事件的问题

    关键词:父子元素关系  mouseout  mouseover  事件  事件冒泡 初期代码: <!DOCTYPE html> <html> <head> < ...

  4. mysql存储引擎(mysql学习六)

    存储引擎 现在只有InnoDB支持外键 上接着学习笔记五 class表中有外键,所以不能修改存储引擎 表类型   默认的服务器表类型,通过my.ini可以配置    Default-storage-e ...

  5. 一款兼容IE6并带有多图横向滚动的jquery特效

    一款兼容IE6并带有多图横向滚动的jquery特效,自动切换多个图片的jquery特效效果, 为大家分享这个的原因是,这款特效在兼容IE6上面很完美,实用性就广很多了. 适用浏览器:IE6.IE7.I ...

  6. win7里开始菜单属性里的隐私项无法选择解决方法

    具体问题如下图,其中的隐私项目呈现灰色无法选择: 解决方法如下: win+R 输入gpedit.msc 回车,[用户配置][管理模板][开始菜单和任务栏],在右侧找到[关闭用户跟踪],双击进入设置界面 ...

  7. 部署到iis后,发现无法加载运行CSS文件

    解决方法: 打开或关闭window功能中的Internet信息服务里的万维网服务=>常见HTTP功能=>静态内容

  8. python 字符串格式化 (%操作符)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在许多编程语言中都包含有格式化字符串的功能,比如C和Fortran语言中的格式化输 ...

  9. ios category

    https://github.com/shaojiankui/IOS-Categories

  10. 微信分享朋友链接显示js代码

    通常自己做的一个页面想通过微信像朋友分享时,展示的标题和描述都是不是自己想要的,自己查了一些资料,原来是通过js来进行控制 展示效果如下: 标题.描述.还有分享的图片都是有js来控制的. js代码如下 ...