HDOJ 1507 Uncle Tom's Inherited Land*
直接对每一个格子进行dfs结果除以2能够得到答案可是有大量反复的结果,不好输出答案.
能够仅仅对横纵坐标相加是奇数的格子dfs....
Uncle Tom's Inherited Land*
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1728 Accepted Submission(s): 723
Special Judge
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).

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.
than one solution, anyone is acceptable. there is a blank line after each test case. See sample below for clarification of the output format.
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
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 <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector> using namespace std; const int dir_x[4]={-1,1,0,0};
const int dir_y[4]={0,0,-1,1}; int mp[120][120];
int n,m,k; bool used[120][120];
int linker[120][120]; bool dfs(int x,int y)
{
for(int i=0;i<4;i++)
{
int X=x+dir_x[i];
int Y=y+dir_y[i];
if(mp[X][Y]==1) continue;
if(X>n||X<1||Y>m||Y<1) continue;
if(used[X][Y]) continue;
used[X][Y]=true;
if(linker[X][Y]==-1||dfs(linker[X][Y]/1000,linker[X][Y]%1000))
{
linker[X][Y]=x*1000+y;
return true;
}
}
return false;
} int hungary()
{
int ret=0;
memset(linker,-1,sizeof(linker));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if((i+j)&1||mp[i][j]==1) continue;
memset(used,false,sizeof(used));
if(dfs(i,j)) ret++;
}
}
return ret;
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF&&n&&m)
{
scanf("%d",&k);
memset(mp,0,sizeof(mp));
for(int i=0;i<k;i++)
{
int a,b;
scanf("%d%d",&a,&b);
mp[a][b]=1;
}
printf("%d\n",hungary());
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int ii=linker[i][j]/1000; int jj=linker[i][j]%1000;
if(jj!=-1)
printf("(%d,%d)--(%d,%d)\n",i,j,ii,jj);
}
}
}
return 0;
}
HDOJ 1507 Uncle Tom's Inherited Land*的更多相关文章
- ZOJ 1516 Uncle Tom's Inherited Land(二分匹配 最大匹配 匈牙利啊)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=516 Your old uncle Tom inherited a p ...
- hdu1507——Uncle Tom's Inherited Land*
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- 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 ...
- 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 ...
- HDU 1507 Uncle Tom's Inherited Land(最大匹配+分奇偶部分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 题目大意:给你一张n*m大小的图,可以将白色正方形凑成1*2的长方形,问你最多可以凑出几块,并输 ...
- HDU 1507 Uncle Tom's Inherited Land*
题目大意:给你一个矩形,然后输入矩形里面池塘的坐标(不能放东西的地方),问可以放的地方中,最多可以放多少块1*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 ...
随机推荐
- 绕过校园网WEB认证_dns2tcp实现
相信很多高校学生都有用WEB认证方式接入校园网的经历 拿我所在的大学为例,我们大学的校园网由联通公司承建,当我连上寝室的无线路由器后,浏览器会自动弹出一个由卓智公司开发的认证界面,如下图: 如果买了联 ...
- Oracle-4 - :超级适合初学者的入门级笔记:plsql,基本语法,记录类型,循环,游标,异常处理,存储过程,存储函数,触发器
初学者可以从查询到现在的pl/sql的内容都可以在我这里的笔记中找到,希望能帮到大家,视频资源在 资源, 我自己的全套笔记在 笔记 在pl/sql中可以继续使用的sql关键字有:update del ...
- C#递归查询
一.sql --构造测试数据: 只作演示用 CREATE TABLE [dbo].[Tim_LinqTable]( [Id] int PRIMARY KEY IDENTITY(1,1) NOT NUL ...
- 北京Python筛选过程中应注意什么
计算机初级爱好者普遍喜欢Python,因为Python干净利索,简单直接.它编写代码的速度非常的快,而且非常注重代码的可读性,非常适合多人参与的项目.很多人选择了培训,那么北京Python培训筛选过程 ...
- jstree 获取选中节点的所有子子点
//加载功能树 function initTree() { $.jstree.destroy(); $.ajax({ type: "Get", url: "/Depart ...
- Linux端图形处理工具ImageMagick在Centos上的安装
一.安装背景程序要用到用户上传图片,编辑的功能,能进行旋转,裁剪,缩放等. 二.ImageMagick介绍 ImageMagick是用C语言开发图片处理程序.可以对图片进行改变大小.旋转.锐化.减色或 ...
- [转载] java多线程学习-java.util.concurrent详解(二)Semaphore/FutureTask/Exchanger
转载自http://janeky.iteye.com/blog/770393 ------------------------------------------------------------- ...
- [转]分布式消息中间件 MetaQ 作者庄晓丹专访
MetaQ(全称Metamorphosis)是一个高性能.高可用.可扩展的分布式消息中间件,思路起源于LinkedIn的Kafka,但并不是Kafka的一个Copy.MetaQ具有消息存储顺序写.吞吐 ...
- spring4新特性-泛型依赖注入
1 文件结构 2 具体类 2.1两个抽象类,在Service里面写公共的方法,在各自的具体实现类里面写各自的方法 package repo;import model.User;/** * Crea ...
- angular指令的简单练习
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...