Uncle Tom's Inherited Land*

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3445    Accepted Submission(s): 1452
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)
 
Source
 题意:n*m的网格,有的不能用,要求相邻的两个小方格为一组,问最多有多少组。
代码:
//简单的二分匹配,相邻的且可用的网格之间建边,求玩=完二分图之后link数组存储的就是答案。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int vis[],link[],nu1[],nu2[],pond[];
int Mu,Mv,n,m,k,last;
vector<int>g[];
bool dfs(int x)
{
for(int i=;i<g[x].size();i++){
int y=g[x][i];
if(!vis[y]){
vis[y]=;
if(link[y]==-||dfs(link[y])){
link[y]=x;
return ;
}
}
}
return ;
}
int Maxcon()
{
int ans=;
memset(link,-,sizeof(link));
for(int i=;i<=n*m;i++){
if(pond[i]) continue;
memset(vis,,sizeof(vis));
if(dfs(i)) ans++;
}
return ans;
}
int main()
{
while(scanf("%d%d",&n,&m)&&(n+m)){
int x,y;
memset(pond,,sizeof(pond));
scanf("%d",&k);
while(k--){
scanf("%d%d",&x,&y);
pond[(x-)*m+y]=;
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
int id=(i-)*m+j;
g[id].clear();
if(i>&&pond[id-m]==) g[id].push_back(id-m);
if(j>&&pond[id-]==) g[id].push_back(id-);
if(i<n&&pond[id+m]==) g[id].push_back(id+m);
if(j<m&&pond[id+]==) g[id].push_back(id+);
}
}
int ans=Maxcon()/;
printf("%d\n",ans);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
int id=(i-)*m+j;
if(link[id]==-||link[link[id]]==-) continue;
printf("(%d,%d)--(%d,%d)\n",i,j,(link[id]-)/m+,link[id]%m==?m:link[id]%m);
link[id]=link[link[id]]=-;
}
}
printf("\n");
}
return ;
}

HDU1507二分图的更多相关文章

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

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

  2. 「日常训练」Uncle Tom's Inherited Land*(HDU-1507)

    题意与分析 题意是这样的:给你一个\(N\times M\)的图,其中有一些点不能放置\(1\times 2\)大小的矩形,矩形可以横着放可以竖着放,问剩下的格子中,最多能够放多少个矩形. 注意到是\ ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  5. bzoj4025 二分图

    支持加边和删边的二分图判定,分治并查集水之(表示我的LCT还很不熟--仅仅停留在极其简单的模板水平). 由于是带权并查集,并且不能路径压缩,所以对权值(到父亲距离的奇偶性)的维护要注意一下. 有一个小 ...

  6. hdu 1281 二分图最大匹配

    对N个可以放棋子的点(X1,Y1),(x2,Y2)......(Xn,Yn);我们把它竖着排看看~(当然X1可以对多个点~) X1   Y1 X2   Y2 X3   Y3 ..... Xn   Yn ...

  7. POJ 2226二分图最大匹配

    匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是二部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图 ...

  8. 二分图&网络流&最小割等问题的总结

    二分图基础: 最大匹配:匈牙利算法 最小点覆盖=最大匹配 最小边覆盖=总节点数-最大匹配 最大独立集=点数-最大匹配 网络流: 技巧: 1.拆点为边,即一个点有限制,可将其转化为边 BZOJ1066, ...

  9. POJ2195 Going Home[费用流|二分图最大权匹配]

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22088   Accepted: 11155 Desc ...

随机推荐

  1. vmware centOS上网配置笔记

    ⦁    修改/etc/sysconfig/network-scripts/ifcfg-eth0文件  (首先查看本机vmware 虚拟网络编辑器中的网关) 重启网络 使用命令:service net ...

  2. 饥饿的小易(枚举+广度优先遍历(BFS))

    题目描述 小易总是感觉饥饿,所以作为章鱼的小易经常出去寻找贝壳吃.最开始小易在一个初始位置x_0.对于小易所处的当前位置x,他只能通过神秘的力量移动到 4 * x + 3或者8 * x + 7.因为使 ...

  3. eos教程如何创建eos测试账号并且使用scatter插件

    EOS代币租赁平台 --- Chintai平台已经在Jungle测试网络上部署了,欢迎大家来体验. 地址见: Chintai 公测版 官网是: Chintai 目前测试网络上面需要用到Scatter插 ...

  4. 1.Hadoop介绍

    1. Hadoop介绍 1.1 什么是Hadoop 开源的,可靠的,分布式的,可伸缩的 提供的功能: 利用服务器集群,根据用户的自定义业务逻辑,对海量数据进行分布式处理 1.2 处理方式 大众角度 数 ...

  5. iOS- 网络访问两种常用方式【GET & POST】实现的几个主要步骤

    1.前言 上次,在博客里谈谈了[GET & POST]的区别,这次准备主要是分享一下自己对[GET & POST]的理解和实现的主要步骤. 在这就不多废话了,直接进主题,有什么不足的欢 ...

  6. 【Docker 命令】- create命令

    docker create :创建一个新的容器但不启动它 语法 docker create [OPTIONS] IMAGE [COMMAND] [ARG...] OPTIONS同run命令 实例 使用 ...

  7. 火狐浏览器(FireFox)安装Flash插件失败处理方法

    最近不知道怎么了,总是嫌弃IE,可能是被网络流量监测的网址给搞得了,弄了火狐浏览器,也安装了猎豹,这里不对浏览器做评价 好多朋友安装好火狐(FireFox)的时候发现之前不是有装IE的Flash播放插 ...

  8. 常见设备在linux中的文件名

    设备 linux中的文件名 IDE硬盘 /dev/hd[a-d] SATA/USB/SCSI/SAS /dev/sd[a-p] 软盘 /dev/fd[0-1] 打印机 25针:/dev/lp[0-2] ...

  9. 关于new delete的说明

    1. 删除空指针不会有问题,因为C++的标准规定在delete时首先会判断指针是否为空,为空就不再处理,所以也就不会有问题. 2. delete一个非空指针之后,并不会将该指针自动置为空.此时如果重复 ...

  10. Android基础------SQLite数据库(一)

    1.SQLite介绍 SQLite是一款非常流行的嵌入式数据库,它支持SQL操作,并且只用很少的内存. Android在运行时集成了SQLite,所有每个Android应用程序都可以使用SQLLite ...