Uncle Tom's Inherited Land*

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3339    Accepted Submission(s): 1394
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)

 【分析】给出一个矩形图 将其中一些格子涂黑 问连续的两个白格子最多多少对。可以将每一个白色格子看成一  个点,然后分成两类 即每个点与他相邻的点分为两类,然后连边 二分图匹配
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#define inf 0x7fffffff
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = ;
const int M = ;
int read() {int x=,f=;char c=getchar();while(c<''||c>'') {if(c=='-')f=-;c=getchar();}while(c>=''&&c<='') {x=x*+c-'';c=getchar();}return x*f;}
int n,m,cnt;
int dis[][]={{,},{,-},{,},{-,}}; int tot,head[N];
int w[][],t[N],x[N],y[N];
struct man
{
int x,y,color,num;
};
struct EDG
{
int to,next;
}edg[M];
struct ANS
{
int x,y;
}answ[N];
void add(int u,int v)
{
edg[cnt].to=v;edg[cnt].next=head[u];head[u]=cnt++;
}
void bfs(int u,int v)
{
queue<man>q;
man s;s.color=;s.num=++tot;s.x=u;s.y=v;q.push(s);
w[u][v]=;answ[tot].x=u;answ[tot].y=v;
while(!q.empty()){
man t=q.front();q.pop();
for(int i=;i<;i++){
int xx=t.x+dis[i][];int yy=t.y+dis[i][];
if(xx>=&&xx<=n&&yy>=&&yy<=m&&!w[xx][yy]){
man k;k.color=(t.color+)%;k.num=++tot;k.x=xx;k.y=yy;
q.push(k);w[xx][yy]=;answ[k.num].x=xx;answ[k.num].y=yy;
if(!t.color)add(t.num,k.num);
else add(k.num,t.num);
}
}
}
}
bool dfs(int u) {
for(int i=head[u];i!=-;i=edg[i].next) {
int v=edg[i].to;
if(!t[v]) {
t[v]=;
if(!y[v]||dfs(y[v])) {
x[u]=v;
y[v]=u;
return true;
}
}
}
return false;
}
void MaxMatch() {
int ans=;
for(int i=; i<=tot; i++) {
if(!x[i]) {
met(t,);
if(dfs(i))ans++;
}
}
printf("%d\n",ans);
for(int i=;i<=tot;i++){
if(x[i]){
int v=x[i];
printf("(%d,%d)--(%d,%d)\n",answ[i].x,answ[i].y,answ[v].x,answ[v].y);
}
}
printf("\n");
}
int main() {
while (~scanf("%d%d",&n,&m)&&n&&m) {
met(w,);met(head,-);met(x,);met(y,);met(edg,);met(answ,);cnt=;tot=;
int k=read();
while(k--){
int x=read();int y=read();
w[x][y]=;
}
for(int i=;i<=n;i++)for(int j=;j<=m;j++)if(!w[i][j])bfs(i,j);
MaxMatch();
}
return ;
}

HDU 1507 Uncle Tom's Inherited Land*(二分图匹配)的更多相关文章

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

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

  3. HDU1507 Uncle Tom's Inherited Land* 二分图匹配 匈牙利算法 黑白染色

    原文链接http://www.cnblogs.com/zhouzhendong/p/8254062.html 题目传送门 - HDU1507 题意概括 有一个n*m的棋盘,有些点是废的. 现在让你用1 ...

  4. HDU 1507 Uncle Tom's Inherited Land(最大匹配+分奇偶部分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 题目大意:给你一张n*m大小的图,可以将白色正方形凑成1*2的长方形,问你最多可以凑出几块,并输 ...

  5. HDU 1507 Uncle Tom's Inherited Land*

    题目大意:给你一个矩形,然后输入矩形里面池塘的坐标(不能放东西的地方),问可以放的地方中,最多可以放多少块1*2的长方形方块,并输出那些方块的位置. 题解:我们将所有未被覆盖的分为两种,即分为黑白格( ...

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

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

  8. hdu1507 Uncle Tom's Inherited Land* 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 将i+j为奇数的构成x集合中 将i+j为偶数的构成y集合中 然后就是构建二部图 关键就是构图 然 ...

  9. XTU 二分图和网络流 练习题 B. Uncle Tom's Inherited Land*

    B. Uncle Tom's Inherited Land* Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I ...

随机推荐

  1. HTML参考

    HTML Basic Document <html> <head> <title>Document name goes here</title> < ...

  2. matlab代码 图像处理源码

    非常不错的找图像处理源码的地方,源码搜搜. http://www.codesoso.com/Category.aspx?CategoryId=56

  3. sql server日志不能shrink或truncate

    Backup log [dbxxx] with truncate_only sql server 2008之后不支持此操作,需要改为: BACKUP LOG dbxxx TO DISK='NUL:' ...

  4. Screen对象

    document.write("Screen-width:"+screen.width+"Screen-height:"+screen.height);docu ...

  5. Js判断键盘按键

    该文转自: namehwh 网址:http://www.cnblogs.com/hanwenhua/articles/3365154.html window.document.onkeydown = ...

  6. GSM短信侦听的便宜方案

    侦听GSM短信常用的是OsmocomBB + C118方案,主要是用luca/gsmmap分支.使用ccch_scan这个程序可以把通信封装成GSMTAP发给本机,然后用WireShark接收GSMT ...

  7. 利用烧鹅制作简单BadUSB,插谁谁怀孕

    所用硬件设备为烧鹅,烧鹅是RadioWar基于Teensy++ 2.0 AT90USB1286芯片设计的USB Rubber Ducky类开发板. 使用veil编码meterpreter生成paylo ...

  8. 初见Gnuplot——时间序列的描述

    研读一本书,<数据之魅:基于开源工具的数据分析>(Data Analysis with Open Source Tools),写的很好.这里,复述一下书中用Gnuplot分析时间序列数据的 ...

  9. HDU4055 - number string(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4055 思路:dp[i][j]表示处理前i个字符以j结尾可能的序列数. 当a[i]=='I'时,dp[i ...

  10. 转:SQL SERVER数据库中实现快速的数据提取和数据分页

    探讨如何在有着1000万条数据的MS SQL SERVER数据库中实现快速的数据提取和数据分页.以下代码说明了我们实例中数据库的“红头文件”一表的部分数据结构: CREATE TABLE [dbo]. ...