Uncle Tom's Inherited Land*
Uncle Tom's Inherited Land* |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
| Total Submission(s): 203 Accepted Submission(s): 132 |
|
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 |
|
Sample Output
4 |
|
Source
South America 2002 - Practice
|
|
Recommend
LL
|
/*
题意:给你一个n*m的方格矩阵,然后有k个方格内有鱼塘,给出你k个鱼塘的坐标,剩下的方格用1*2的小方格填满,问你最多能填多少个 初步思路:对剩下的小方格进行二分匹配,只有两个相邻的小方格才存在联系,能填满的最大数,就是二分的最大匹配数;
#超内存 因为开标记数组的时候把鱼塘也考虑进去了,所以开了一个10000*10000的数组,太大 改进:总共空格子最多有50个,只需要开一个50*50的数组就可以
*/
#include<bits/stdc++.h>
#define N 110
using namespace std;
int mapn[N][N];
int vis[N][N];
int vis2[N][N];
int n,m,k;
int x,y;
int dir[][]={{,},{-,},{,-},{,}};
struct node{
int x,y;
node(){}
node(int a,int b){
x=a;
y=b;
}
};
vector<node>point;
/***********************二分匹配模板**************************/
const int MAXN=;
int uN,vN; //u,v数目
int g[][];//编号是0~n-1的
int linker[MAXN];//记录匹配点i的匹配点是谁
bool used[MAXN];
bool dfs(int u)//回溯看能不能通过分手来进行匹配
{
int v;
for(v=;v<point.size();v++)
if(g[u][v]&&!used[v])
//如果有这条边,并且这条边没有用过
{
used[v]=true;
if(linker[v]==-||dfs(linker[v]))//如果这个点没有匹配过,并且能找到匹配点,那么就可以以这个边作为匹配点
{
linker[v]=u;
return true;
}
}
return false;
}
int hungary()//返回最大匹配数
{
int res=;
int u;
memset(linker,-,sizeof(linker));
for(u=;u<point.size();u++)
{
memset(used,,sizeof(used));
if(dfs(u))//如果这个点有匹配点
res++;
}
return res;
}
/***********************二分匹配模板**************************/
void init(){
memset(g,,sizeof g);
memset(mapn,,sizeof mapn);
memset(vis,,sizeof vis);
memset(vis2,,sizeof vis2);
point.clear();
}
bool ok(int x,int y){
if(x<||x>n||y<||y>m||mapn[x][y]) return true;
return false;
}
void match(){//将所有的小方格进行编号 for(int i=;i<=n;i++){//将所有的空方格存进vector中
for(int j=;j<=m;j++){
//cout<<mapn[i][j]<<" ";
if(mapn[i][j]==)
{
point.push_back(node(i,j));
vis2[i][j]=point.size()-;//记录这是第几个
//cout<<i<<" "<<j<<endl;
}
}
//cout<<endl;
}
//cout<<"point.size()="<<point.size()<<endl;
for(int i=;i<point.size();i++){
if(vis[point[i].x][point[i].y]==){
vis[point[i].x][point[i].y]=;
for(int k=;k<;k++){
int fx=point[i].x+dir[k][];
int fy=point[i].y+dir[k][];
if(ok(fx,fy)) continue;
g[i][vis2[fx][fy]]=;
vis[fx][fy]=;
}
}
}
// for(int i=0;i<point.size();i++){
// for(int j=0;j<point.size();j++){
// cout<<g[i][j]<<" ";
// }
// cout<<endl;
// }
}
int main(){
//freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF&&(n+m)){
init();//初始化
scanf("%d",&k);
while(k--){
scanf("%d%d",&x,&y);
mapn[x][y]=;
}//标记鱼塘的位置
// for(int i=1;i<=n;i++){
// for(int j=1;j<=m;j++){
// cout<<mapn[i][j]<<" ";
// }
// cout<<endl;
// }
match();//进行空格的匹配
int cur=hungary();
printf("%d\n",cur);
for(int i=;i<point.size();i++){
if(linker[i]!=-){
printf("(%d,%d)--(%d,%d)\n",point[i].x,point[i].y,point[linker[i]].x,point[linker[i]].y);
}
}
printf("\n");
}
return ;
}
Uncle Tom's Inherited Land*的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- ZOJ1516 Uncle Tom's Inherited Land(二分图最大匹配)
一个经典的构图:对格子进行黑白染色,黑白的点分别作XY部的点. 这一题的边就是可以出售的单位面积2的土地,边的端点就是这个土地占用的X部和Y部的两个点. 这样就建好二分图,要求最多土地的答案显然是这个 ...
- HDU 1507 Uncle Tom's Inherited Land*
题目大意:给你一个矩形,然后输入矩形里面池塘的坐标(不能放东西的地方),问可以放的地方中,最多可以放多少块1*2的长方形方块,并输出那些方块的位置. 题解:我们将所有未被覆盖的分为两种,即分为黑白格( ...
- hdu1507 Uncle Tom's Inherited Land* 二分匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 将i+j为奇数的构成x集合中 将i+j为偶数的构成y集合中 然后就是构建二部图 关键就是构图 然 ...
随机推荐
- MySQL所学所思所想
MySQL更改线上配置方案思想:原则上,需要备机.备份工作准备到位,有参数调优配置方案.有配置回退方案.有应急切换备机方案.以上方案评审无问题,然后可以和客户约定实施的时间.服务中断时间,先向客户侧申 ...
- 移植Linux-3.4.2内核到S3C2440
一.BootLoader引导内核过程 1.Bootloader的工作 1.1.将内核读入内存 2.2.保存内核启动参数到指定位置,内核启动时去这个位置解析参数 3.3. ...
- 无限树Jquery插件zTree的使用方法
其实Ztree官网已经有详细的API文档,一切以官网上的说明为准,我在此只是结合实践总结几条常用的ztree的功能特性. (ztree的语法结构是基于key-value的形式配置) 1:支持异步加载数 ...
- 分享基于分布式Http长连接框架--代码模型
好的代码应该是方便客户端使用,代码能够自描述,规范化,大众标准化. 而且我相信代码也是有生命的,需要不断的维护它,你以什么样的态度对待它,它就会以同样的态度回敬你,所以在写代码前,先摆好自己的态度(一 ...
- 【BZOJ】2190 [SDOI2008]仪仗队(欧拉函数)
Description 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是 ...
- java数据库编程之数据库的设计
第一章:数据库的设计 1.1:为什么需要规范数据库的设计 1.1.1:什么是数据库设计 数据库设计就是将数据中的数据实体及这些数据实体之间的关系,进行规范和结构的过程. 1.1.2:数据库设计非常重要 ...
- Python自学笔记-paramiko模块(Mr serven)
文章出处:http://www.cnblogs.com/wupeiqi/articles/5095821.html SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码连接: #!/u ...
- webpack2使用ch5-多页面设置 内部js和引入js
1 当前目录 2 webpack.config.js 配置 const webpack = require('webpack'), htmlWebpackPlugin = require('html- ...
- Java面向对象(封装性概论)
Java面向对象(封装性概论) 知识概要: (1)面向对象概念 (2)类与对象的关系 (3)封装 (4)构造函数 (5)this关键字 (6)static关键 ...
- jS判断浏览器终端
在做移动端项目的时候,常常会遇到需要判断页面浏览终端的需求.要想判断是什么浏览器终端,先打印 navigator.userAgent 出来.所以收集了几种比较常用的方法: if(/(iPhone|iP ...
