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



CANoe连接Option Scope使用方法 本文档主要介绍如何使用CANoe Option .Scope捕获CAN总线上的物理波形,并利用眼图进行分析。 阅读详情

相关推荐

RK3568平台 麦克风PDM接口录音_rk pdm配置

在RK平台,Android的Audio HAL层中一般会都会有导出录音播放数据的功能。如播放的,是会直接送到声卡中的,对于播放出现问题的情况,可以从分析导出的音频数据是否正常,可以基本知道,是在应用、解码出现的问题,还是送到声卡过程中出现问题。当点开app进行录音的时候会调用到static int start_input_stream(struct stream_in *in)。音频在PDM接口输入,不经过编解码芯片直接到RK主芯片,RK主芯片自带PCM编解码功能。以下软件能播放保存下来的pdm文件。

2401_83817122的博客 2346

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

别再瞎试了!手把手教你用DC NXT的compile_ultra命令搞定物理综合(附完整脚本)

本文详细介绍了如何使用DC NXT的compile_ultra命令进行物理综合,包括环境配置、设计库创建、RTL加载、物理约束加载等关键步骤。通过实战示例和完整脚本,帮助工程师快速掌握TOPO模式下的物理综合流程,提升设计效率。

weixin_30413765的博客 299

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的博客 172

新能源车主必看:用高德API+充电站数据制作跨城出行充电规划工具(附完整代码)

本文为新能源车主提供了一份详细的跨城出行充电规划工具构建指南。通过整合高德地图API与充电站数据,手把手教你使用Python开发一个智能规划系统,可自动规划路线并推荐沿途充电站,有效缓解里程焦虑。文章包含完整代码、核心算法解析及可视化实现,帮助车主实现个性化、高效的出行规划。

tgb3456789的博客 909

AES-GCM加密认证模式:原理、优势与实战应用

在数据安全领域,加密与认证是保障信息机密性和完整性的两大基石。加密确保数据内容不被窃取,而认证则验证数据来源的真实性和传输过程中是否被篡改。传统的加密后认证方案如AES-CBC+HMAC需要串行处理,性能开销较大。GCM(伽罗瓦/计数器模式)作为一种认证加密(AEAD)方案,巧妙地将AES-CTR加密与基于伽罗瓦域的GHASH认证并行结合,实现了单次数据遍历即可同时完成加密和认证,大幅提升了处理效率。其核心价值在于高性能、支持附加认证数据(AAD)以及标准化程度高,广泛应用于TLS协议、无线网络安全和云存储

weixin_28622215的博客 341

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

AIDC供电系统与算电协同

AIDC供电系统的技术革新为算电协同提供了基础保障,而算电协同则是解决AIDC高能耗问题、推动数字经济可持续发展的关键路径

数据中心全生命周期价值管理 2588

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的博客 204

从零开始构建AURIX TC397开发环境:硬件选型与IDE配置全攻略

本文详细介绍了如何从零开始构建AURIX TC397开发环境,涵盖硬件选型、IDE配置及外设驱动开发等关键步骤。针对TriCore架构的高性能特性,提供了开发板选型建议、AURIX Development Studio(ADS)安装配置指南,以及GPIO和CAN FD驱动的实战代码示例,帮助开发者快速上手TC397系列微控制器的开发工作。

7up55的博客 218

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

hdu 1507 Uncle Tom's Inherited Land*

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

uuuuuu 480

Camera2Demo

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

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

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

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

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

ンZee的解题报告 2074

HDU1507 - Uncle Tom's Inherited Land*

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

345

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的专栏 597

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

余额充值