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. tomcat学习笔记2

    LNMT在网站架构中的实现过程: Client --> http --> Nginx --> reverse_proxy (http) --> tomcat (http con ...

  2. 等价表达式 (codevs 1107)题解

    [问题描述] 明明进了中学之后,学到了代数表达式.有一天,他碰到一个很麻烦的选择题.这个题目的题干中首先给出了一个代数表达式,然后列出了若干选项,每个选项也是一个代数表达式,题目的要求是判断选项中哪些 ...

  3. 解决dropdownlist postback 在 iphone UIwebview 失效的问题

    原因: IPhone UIWebView 的 用户代理 User Agent 在ASP.NET 4.0环境下是不识别的:所以ASP.NET提供了一个默认的,低级的不包括javascript的页面版本 ...

  4. [转载]--Ubuntu下修改DNS重启也能用的方法

    安装好Ubuntu之后设置了静态IP地址,再重启后就无法解析域名.想重新设置一下DNS,打开/etc/resolv.conf cat /etc/resolv.conf# Dynamic resolv. ...

  5. 多点触摸画板(MultiTouchCanvas)

    这是个简单的支持多点触摸的画板控件, 绘制功能基于WPF InkCanvas,也是我drawTool系列文章的开篇. 阅读该文章后可能产生一些问题: 1. 如果对生成的笔迹对象进行控制 如果要对生成的 ...

  6. Window7上搭建symfony开发环境(PEAR)

    http://blog.csdn.net/kunshan_shenbin/article/details/7162243 1. 更新PEAR 进入PHP所在目录,找到go-pear.bat并双击. 一 ...

  7. iPhone的震动 基于SDK8.0 Swift实现

    导入AudioToolbox.framework包 在swift文件中  import AudioToolbox AudioServicesPlaySystemSound(SystemSoundID. ...

  8. 第三方登录开发-Facebook

    这次这个项目要分别可以使用新浪微博,qq互联以及Facebook和Twitter授权登录 facebook目前只支持oauth2技术,个人理解其工作流程是当用户想访问当前网站,却不想注册账号,此时当前 ...

  9. with check option

    通过有with check option选项的视图操作基表(只是面对单表,对连接多表的视图正在寻找答案),有以下结论:首先视图只操作它可以查询出来的数据,对于它查询不出的数据,即使基表有,也不可以通过 ...

  10. 服务器 IIS 发布网站 支持下载 apk 和 ipa

    方法/步骤   1 打开IIS服务管理器,找到服务器,右键-属性,打开IIS服务属性: 2 单击MIME类型下的"MIME类型"按钮,打开MIME类型设置窗口: 3 单击" ...