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 (Java/Others)
Total Submission(s): 1869 Accepted Submission(s): 777
Special Judge
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).
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.
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.
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)
题意就是找出最多的1*2的方块来,UP主的主要思路为:以i+j的奇偶性为分类,因为每个1*2的方块肯定是由一个奇点和一个偶点构成,二分图是思路都是某个东西由2类东西构成,再去用匈牙利算法,然后再用map数组偶点存匹配的方向
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int map[105][105];
bool vis[105][105];
int d[5][2]={{0,0},{1,0},{0,1},{-1,0},{0,-1}};
int x, y;
void myscanf()
{
memset(map,0,sizeof(map));
int m, a, b;
scanf("%d",&m);
while(m--)
{
scanf("%d%d",&a,&b);
map[a][b] = -1;
}
} void myprintf(int xi, int yi)
{
int f = map[xi][yi];
int fx = d[f][0] + xi;
int fy = d[f][1] + yi;
printf("(%d,%d)--(%d,%d)\n",xi,yi,fx,fy);
} bool pd(int xi, int yi)
{
if(xi<=0 || xi>x || yi<=0 || yi>y || map[xi][yi]==-1) return false;
return true;
} bool dfs(int xi,int yi)
{
for(int i=1;i<=4;i++)
{
int fx = xi+d[i][0];
int fy = yi+d[i][1];
if(pd(fx,fy) && !vis[fx][fy])
{
vis[fx][fy] = true;
int f = map[fx][fy];
int ex = fx + d[f][0];
int ey = fy + d[f][1];
if(!f || dfs(ex,ey))
{
map[fx][fy] = (i+2)%4==0?4:(i+2)%4;
return true;
}
}
}
return false;
} int find()
{
int res = 0;
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
if((i+j)%2)
{
memset(vis,0,sizeof(vis));
if(map[i][j]==-1) continue;
if(dfs(i,j)) res++;
}
}
}
return res;
} int main()
{
// freopen("in.txt","r+",stdin);
// freopen("out1.txt","w+",stdout);
while(scanf("%d%d",&x,&y)!=EOF)
{
if(x==0 && y==0) break;
myscanf();
cout<<find()<<endl;
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
if(map[i][j]>0)
{
myprintf(i,j);
}
}
}
printf("\n");
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏的更多相关文章
- 修改MS SQL忽略大小写 分类: SQL Server 数据库 2015-06-19 09:18 34人阅读 评论(0) 收藏
第一步:数据库->属性->选项->限制访问:SINGLE_USER 第二步:ALTER DATABASE [数据库名称] collate Chinese_PRC_CI_AI 第三步: ...
- *** glibc detected *** malloc(): memory corruption 分类: C/C++ Linux 2015-05-14 09:22 37人阅读 评论(0) 收藏
*** glibc detected *** malloc(): memory corruption: 0x09eab988 *** 发现是由于memset越界写引起的. 在Linux Server上 ...
- 哈希-4 Values whose Sum is 0 分类: POJ 哈希 2015-08-07 09:51 3人阅读 评论(0) 收藏
4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 17875 Accepted: ...
- 哈希-Gold Balanced Lineup 分类: POJ 哈希 2015-08-07 09:04 2人阅读 评论(0) 收藏
Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13215 Accepted: 3873 ...
- nginx 安装手记 分类: Nginx 服务器搭建 2015-07-14 14:28 15人阅读 评论(0) 收藏
Nginx需要依赖下面3个包 gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ ) zlib-1.2.8.tar.gz rewrite 模块需要 pcre 库 ( ...
- 快速查询本机IP 分类: windows常用小技巧 2014-04-15 09:28 138人阅读 评论(0) 收藏
第一步: 点击windows建(屏幕左下方),在搜索程序和文件文本框内输入:cmd 第二步: 点击Enter建进入. 第三步: 输入:ipconfig即可. 版权声明:本文为博主原创文章,未 ...
- 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 ...
- sscanf 函数 分类: POJ 2015-08-04 09:19 4人阅读 评论(0) 收藏
sscanf 其实很强大 分类: 纯C技术 技术笔记 2010-03-05 16:00 12133人阅读 评论(4) 收藏 举报 正则表达式stringbuffercurlgoogle 最近在做日志分 ...
随机推荐
- 不加班的实践(1)——这真的该用try-catch吗?
前言 我有个技能,就是把“我”说的听起来特别像“老子”. 以前是小喽啰的时候,会跟领导说“我!不加班.”,听起来就像“老子不加班!”一样.到最后发现,我确实没有把计划内的工作拖到需要加班才能完成,这个 ...
- delphi android 中 Toast 的实现(老外写的UNIT)
unit Android.JNI.Toast; // Java bridge class imported by hand by Brian Long (http://blong.com)interf ...
- 下一代NoSQL:最终一致性的末日
相比关系型数据库,NoSQL解决方案提供了shared-nothing.容错和可扩展的分布式架构等特性,同时也放弃了关系型数据库的强数据一致性和隔离性,美其名曰:"最终一致性". ...
- 第七节:使用实现了dispose模式的类型
知道类型如何实现dispose模式之后,接下来看一下开发人员怎样使用提供了dispose模式的类型.这里不再讨论前面的SafeHandle类,而是讨论更常用的FileStream类. 可以利用File ...
- NOJ1019-计算二叉树的高度和结点数
输入 二叉树的先序遍历序列,用#代表空树或空子树. 输出 共五行 前三行依次输出先序.中序和后序遍历序列, 第四行输出二叉树的高度, 第五行依次输出二叉树总结点数目.叶子结点数目.度为1的结点数目. ...
- 使用Handler和Timer+Timertask实现简单的图片轮播
布局文件就只放了一个简单的ImageView,就不展示了. 下面是Activity package com.example.administrator.handlerthreadmessagedemo ...
- Android操作系统11种传感器介绍
我们依次看看这十一种传感器 1 加速度传感器 加速度传感器又叫G-sensor,返回x.y.z三轴的加速度数值. 该数值包含地心引力的影响,单位是m/s^2. 将手机平放在桌面上,x轴默认为0,y轴默 ...
- JavaScript高级程序设计之函数性能
setTimeout 比 setInterval 性能更好 // 取代setInterval setTimeout(function self () { // code goes here setTi ...
- VS2010遇到_WIN32_WINNT宏定义问题
最近拿到一个别人的工程,是使用VS.net创建的,而我的机器上只有vs2010,于是用自带的转换工具将它转换成vs2010的工程,转换之前我就很担心,怕转换完后会出问题,但是没有办法,我实在是不想再安 ...
- Windows下使用Visual Studio Code搭建Go语言环境
1.安装GO语言 下载地址: https://golang.org/dl/ Windows下直接运行安装GO语言即可. 安装成功. 安装完毕GO语言后,需要添加GOPATH环 ...