Hdu 1507 Uncle Tom's Inherited Land*

Tom Cat (汤姆猫) Java小游戏Tom Cat /////////////////////// ////////////////////// ///////////////////// 立即下载

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


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)

题意就是找出最多的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;
}



相关推荐

QT项目实战:如何在正点原子Linux开发板上集成CVR-100UC身份证阅读器(附完整代码)

本文详细介绍了在正点原子Linux开发板上集成CVR-100UC身份证阅读器的完整实战流程。内容涵盖驱动适配、库文件部署、QT项目框架搭建、核心功能封装以及界面集成,并提供了完整的代码示例,帮助开发者快速实现嵌入式环境下的身份证信息读取功能。

yyy34的博客 257

06-TOM汤姆猫

// // ViewController.m // 06-TOM汤姆猫 // // Created by yibooo on 16/1/17. // Copyright © 2016年 yibooo. All rights reserved. //import “ViewController.h”@interface ViewController ()@property (wea

yibo_oo的博客 6万+

新手避坑指南:用Silvaco Atlas搞定GaN HEMT电热仿真的完整流程(附代码解读)

本文详细介绍了使用Silvaco Atlas进行GaN HEMT电热特性仿真的完整流程,特别针对新手常见问题提供避坑指南。从软件环境配置、结构定义、网格划分到物理模型设置,逐步解析关键步骤,并附有代码解读和调试技巧,帮助读者快速掌握GaN器件仿真的核心技术。

weixin_29215815的博客 595

HDU 1507 Uncle Tom's Inherited Land*

Uncle Tom's Inherited Land* Time Limit : 2000/1000ms (Java/Other)Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 11Accepted Submission(s) : 7 Special Judge Problem Descri...

anvt77205的博客 171

西门子S7-1200的PID应用(恒温热水器)

物料清单:1200PLC一台,模拟量输入模块SM1231(PLC自带的输入通道不支持4-20mA电流输入)一个,PT100一个,温度变送器,热得快,固态继电器。 第一步,硬件接线; 第二步,新建1200工程,添加PLC和模拟量输入模块,修改模块的模拟量输入类型为4-20mA,模拟量模块的IO地址为96-103(8个字); 第三步,新建循环组织块OB30,循环时间选择默认点1...

weixin_30835649的博客 6549

贝叶斯时空模型-INLA-4

该文章中,会简化数学计算的过程,主要是针对,在有数据的基础上,如何应用贝叶斯时空模型,找出影响因素,绘制时间变化的空间分布预测图。上述中关键一步与前几期介绍的不一样的地方是,我们加入了n.group参数,用来指定年份,先看一下Year有多少年的,然后封装在s.index里面。在前述的内容中,我们介绍了,如何处理空间的数据,利用海拔高度预测降雨量的例子。建立好数据及mesh以后,我们现在写INLA公式,如果不考虑残差项,那就是固定效应,现在我们增加残差项,及空间与时间效应。这里的Mesh设定值为10,20。

学习中 2947

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 Limit: 65536/32768 K (Java/Others)Total Submission(s): 3671Accepted Submission(s): 1554Special...

agcozdwdfvds08078的博客 255

《FPGA接口与协议》专栏的说明与导航

《FPGA接口与协议》专栏的说明与导航(建议阅读)。

孤独的单刀 17万+

HDU-1507-Uncle Tom's Inherited Land*

链接:https://vjudge.net/problem/HDU-1507 题意: 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, ho...

weixin_34018169的博客 203

使用ArcGIS Pro进行土地利用分类的机器学习与深度学习

传统的土地利用分类方法通常依赖于手动解译和规则定义,但随着机器学习和深度学习的发展,我们现在可以利用这些技术来自动化和提高分类的精度。ArcGIS Pro是一种功能强大的GIS软件,它提供了丰富的工具和功能,可以支持土地利用分类的机器学习和深度学习。我们将首先讨论数据准备和预处理的步骤,然后介绍常用的机器学习和深度学习方法,并提供相应的源代码示例。这可以通过人工标注或半自动的方式完成。数据裁剪:根据研究区域的范围,裁剪遥感影像数据,以减少计算和存储的负担,并确保只包含感兴趣的土地利用区域。

code_program481的博客 2039

RK3588开发笔记-MIPI-CSI接口视频解码芯片XS9922B调试

Rockchip RK3588 是一款高性能的处理器,支持多种摄像头接口,包括 MIPI(Mobile Industry Processor Interface)接口。MIPI是一种用于移动设备和嵌入式系统中的摄像头、显示器和其他传感器设备的串行接口标准。MIPI是MIPI联盟发起的为移动应用处理器制定的开放标准。CSI-2(Camera Serial Interface 2)是MIPI 联盟定义的另一种高速接口,主要用于摄像模组和处理器之间的连接。

flypig has a dream! 6860

hdu 1507 Uncle Tom's Inherited Land*

给出一张n*m的图 二分图的行列式匹配。

uuuuuu 480

xilinx原语及bank简介

图8是HP bank与HR bank的IO模块,其中PAD是FPGA的金属管脚,IOB是输入、输出引脚的控制模块。此时使用原语就可以只调用需要的组件,不需要去考虑其余组件参数设置,就方便很多,借助此次机会就对IDDR、ODDR、IDELAYE2、ODELAYE2、IDELAYCRTL、ISERDESE、OSERDESE等几个原语做了简要了解,并对原语的各个模式进行了仿真,本文最初是介绍IDDR的,但在介绍IDDR这些原语之前,还需要了解一下7系列FPGA bank的分类和区别,所以就有了本文。

qq_43416206的博客 411

hdu 1507【Uncle Tom's Inherited Land*】

#include <cstdio> #include <cstring> #include <vector> using namespace std; vector<int> land[100]; int link[100]; bool vis[100]; int g[110][110]; bool vis2[1...

aoyuan4706的博客 123

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

hdu 1507 Uncle Tom's Inherited Land* (棋盘的完美覆盖问题)

题目链接:   hdu 1507 题目大意:   给出NxM的地图,地图上有空地和草地                   用1x2的草地去覆盖空地,问最多覆盖数 解题思路:   首先1x2的草地,涉及到两个相邻的空地                   若先选择第一个空地,则在没有草地的前提下第二个空地有四种选择                   分别从图中不同块任意一个顶点

ンZee的解题报告 2073

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

HDU1507 - Uncle Tom's Inherited Land*

奇偶点匹配(就是国际象棋盘的红黑格子匹配)

345

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

HDU 1507 Uncle Tom's Inherited Land*

http://acm.hdu.edu.cn/showproblem.php?pid=1507#include using namespace std; #define N 10001 struct node{ int next,v; node(){};

ME4546的专栏 861

HDU 1507 — Uncle Tom's Inherited Land*

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1507 题意: 给定一个n*m的矩阵,以及k个点(表示坏点,无法铺设); 接下来K行给出这些点的坐标; 问最多可以铺设几个1*2的格子,并输出匹配方式; 思路: 将能组成1*2方格的两个坐标相连,然后求最大匹配; 二维坐标均用一维表示; #include #inclu

吧唧吧唧 523

HDU 1507 Uncle Tom's Inherited Land* 二分图最大匹配

题意:有N*N的地,其中有些是水池,如果空地形成1*2的大小就可以卖掉。问:最多可以卖掉多少块空地?输出每块空地在N*N矩阵中的位置。思路:(i+j)是奇数的作为X部,(i+j)是偶数的作为Y部,空格相邻就连一条线,找最大匹配即可。 http://acm.hdu.edu.cn/showproblem.php?pid=1507 /**********************************

NM的专栏 596

hdu1507——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): 2114    Accepted Submission(s): 867 Special Judge Problem Des

Alex 935
上一篇: Poj 1255 覆盖的面积
下一篇: HDU 1532 Drainage Ditches
梁千仞
博客等级 码龄15年 12粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值