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 ...
随机推荐
- 转:ef获取某个表中的部分字段值
我有个新闻表 id,title,body,createtime,author,click 使用ef4.1 仅仅读取 id,title,createtime 并显示在页面上. public static ...
- 【APP问题定位(三)】adb安装
先来剧透一下我们需要使用的工具 bin包 一个安装目录,可以免安装直接调用adb命令 Android SDK platform tools 下面依次为大家介绍,第1个和第2 ...
- 对于ES6中Promise的个人见解
1.js中常见的异步 JavaScript可以响应用户的一些异步交互,比如单击鼠标和按键盘等操作. let button = document.getElementById("btn&quo ...
- Oracle与Sql server的区别
一直搞不明白Oracle数据库和sql server的区别,今天我特意查资料把他们的区别整理出来 Oracle数据库:Oracle Database,又名Oracle RDBMS,或简称Oracle. ...
- ASP.Net Controls 用法大全
The FindControl method of the System.Web.UI.Control class appears simple enough to use. In fact, the ...
- key-value数据库-Redis
1.简介 Redis是完全开源的ANSI C语言编写.遵守BSD协议,高性能的key-value数据库. 1.1特点 Redis支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载 ...
- 那些年我们写js烦的不疼不痒的错误
1.Js 字符变量不加双/单引号. 列如:var strJsonInfo = '@Html.Raw(ViewBag.JsonInfo)'; 2.js 对象初始化器,最后一个属性值加逗号. 例如:var ...
- .net 系列:事件和委托
在.net 的世界里,离不开委托和事件,其实理解透了后很简单,总结了一下分为5步: 1)定义委托 public delegate void RevicedEventHandler(object ...
- Cocos2D-X屏幕适配新解
” 阅读器 为了适应移动终端的各种分辨率大小,各种屏幕宽高比,在 Cocos2D-X(当前稳定版:2.0.4) 中,提供了相应的解决方案,以方便我们在设计游戏时,能够更好的适应不同的环境. 而 ...
- HTML5开发必备的工具
现在除了移动APP开发之外,比较火的就是html5开发了,现阶段的HTML5被看做是Web开发者创建流行web应用的利器,增加了对视频和Canvas2D的支持,它的优点就是可以跨平台使用,比如你是开发 ...