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. js获取和设置DOM样式函数cssStyle(类似于jquery的$(elem).css())

    如题,相信这个函数百度一搜一大推,但令人匪夷所思的是这些函数都写的“奇形怪状的”,例如http://www.cnblogs.com/windows7/archive/2010/03/30/170064 ...

  2. 让TextView出现跑马灯效果

    只需要在TextView中添加一些属性即可: <?xml version="1.0" encoding="utf-8"?> <LinearLa ...

  3. MVC中Model,不仅仅只是数据的传递者

    在Model使用的时候很多人回向以前写三层架构一样使用它,将Model作为数据的传递者. 比如常见的写法 public int Id { get; set; } public int RoleId { ...

  4. 为啥 Objective-C 使用中括号来调用类方法?

    原因在这篇文章中:http://stackoverflow.com/questions/23723838/why-does-objective-c-use-square-brackets-for-me ...

  5. HelloWorld IL代码

    .assembly extern mscorlib .assembly HelloWorld.class HelloWorld extends [mscorlib] System.Object {   ...

  6. C 简单处理excel 转成 json

    引言 工作中常需要处理excel转json问题. 希望这篇博文能简单描述这个问题.并提供一种解决思路.提升感悟. 今天我们处理的事就是为了把 xlsm => json. 一种方式是. 去 goo ...

  7. linux rm 命令

    1.命令格式: rm [选项] 文件… 2.命令功能: 删除一个目录中的一个或多个文件或目录,如果没有使用- r选项,则rm不会删除目录.如果使用 rm 来删除文件,通常仍可以将该文件恢复原状. 3. ...

  8. oracle 表迁移方法 (二) 约束不失效

    DB:11.2.0.3.0 在oracle 表迁移方法 (一)中,只是move了一张普通的表,如果表的字段带有主键约束呢 ? [oracle@db01 ~]$ sqlplus / as sysdba ...

  9. Repair the database using DBCC CHECKDB

    So now if you want to place AdventureWorks2008R2 sample database in a single-user mode, then write t ...

  10. mac media server

    近日在mac osx基于开源组件nginx-rtmp-module架设了一台默认的media server,以下是过程笔记 下载https://github.com/arut/nginx-rtmp-m ...