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;
}



DDR内存接口深度解析:从寻址机制到FPGA时序约束实战 在高速数字系统设计中,内存接口是决定系统性能与稳定性的关键。DDR(双倍数据速率)技术通过在时钟的上升沿和下降沿传输数据,实现了带宽的倍增,广泛应用于消费电子、通信设备和工控主板等领域。其核心原理在于利用三维存储阵列(Bank、Row、Column)的分级寻址机制,通过先进行行激活、再进行列访问的固定时序,实现高速数据吞吐。理解这一寻址顺序是进行精准时序分析的基础。在工程实践中,FPGA作为内存控制器,需通过严谨的时序约束(如set_input_delay)来确保信号在高速传输下的建立与保持时间要求,从而将 阅读详情

相关推荐

第三篇:AMD 和 Intel

它像“乐高积木”一样,可以通过标准化的接口与其他部分组合,构建复杂系统。理解组件后,你会发现从操作系统到微服务,现代软件本质上都是组件的组合!

u013089100的博客 1030

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万+

Yersinia:layer 2攻击框架!全参数详细教程!Kali Linux教程!

Yersinia是一个专为执行二层网络攻击设计的框架,利用多种网络协议的弱点进行渗透测试和网络分析。它支持针对生成树协议(STP)、思科发现协议(CDP)、动态中继协议(DTP)、动态主机配置协议(DHCP)、热备用路由器协议(HSRP)、802.1q、802.1x、交换机间链路协议(ISL)和VLAN中继协议(VTP)的攻击。这些攻击可能导致网络中的拒绝服务(DoS)或为更复杂的攻击创造条件。Yersinia对渗透测试人员和网络管理员非常有用,但使用时需谨慎,以免造成网络不稳定。

qq_24305079的博客 2281

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

Pattern Recognition 投稿过程记录,含Elsevier Latex模板使用

Pattern Recognition 投稿过程记录,含Elsevier Latex模板使用 最近在Pattern Recognition投出了一个文章,纯纯属于是第一次投稿,感觉自己写了一坨屎,事实是这确实也是一坨屎,现在是投了之后在等待一个拒稿的状态。 但是还是记录一下一些流程 1. 下载模板 在出版商Elsevier的栏目里有对于稿件的结构要求,也提供了Latex模板。同时,也给作者提供了Guides, 可以仔细阅读。下面这个连接咱们可以下载到Guides以及看到一些文章的要求。 https://ww

weixin_44153180的博客 3万+

UDS $27服务DLL文件生成

UDS 27算法 DLL文件生成

hkj8808的博客 1282

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

告别手动!用Python+CATIA V5/V6自动生成三视图和标题栏(附完整代码)

本文详细介绍了如何利用Python和CATIA V5/V6实现工程图自动生成,包括三视图布局和标题栏填写。通过COM接口调用和智能算法,系统能自适应不同尺寸模型,大幅提升设计效率。附完整代码和部署方案,帮助团队实现从手动到自动化的转变。

weixin_42699679的博客 351

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

从课堂笔记到动手实践:用Multisim仿真高频谐振功放(丙类)的完整流程

本文详细介绍了使用Multisim仿真高频谐振功放(丙类)的完整流程,从仿真环境准备到电路搭建、偏置网络设计、信号注入与波形观测,再到效率优化与性能验证。通过14个关键操作步骤,帮助读者将高频电子线路的理论知识转化为动手实践,深入理解丙类功放的非线性工作状态和效率优化技巧。

weixin_30701575的博客 518

物理与工程中的‘黑话’:Kronecker delta和Levi-Civita符号到底简化了什么?

本文深入解析了物理与工程中常用的Kronecker delta和Levi-Civita符号的简化作用。通过对比传统表示与张量表示,展示了这些符号在向量运算、矩阵迹计算及流体力学模拟中的高效应用,显著提升计算效率和代码可读性。特别适合理论物理和工程数学领域的学习者与从业者。

weixin_27215403的博客 397

hdu 1507 Uncle Tom's Inherited Land*

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

uuuuuu 480

展锐平台wifi连接性问题解决方案

对于断开连接的问题,需要从kernel log中确认下,是上 层主动发起的断开(会下发disconnect的命令),还是CP侧上报的断开事件。同学,别退出呀,我可是全网最牛逼的 WIFI/BT/GPS/NFC分析博主,我写了上百篇文章,请点击下面了解本专栏,进入本博主主页看看再走呗,一定不会让你后悔的,记得一定要去看主页置顶文章哦。1、出现wifi连接正常,但无法上网问题,首先确认其他手机是否可以正常上网,排除网络自身问题;3 路由器配置问题,出现过一个案例,恢复出场设置问题就解决了,具体根因。

手机-手表蓝牙开发工程师的博客 2022

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

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

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

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

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

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

ンZee的解题报告 2073

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

HDU1507 - Uncle Tom's Inherited Land*

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

345

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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、付费专栏及课程。

余额充值