hdu1507——Uncle Tom's Inherited Land*

ZOJ 1516--Uncle Tom's Inherited Land【二分图 && 求最大匹配数 && 经典建图】 Uncle Tom's Inherited Land Time Limit: 2 Seconds      Memory Limit: 65536 KB Your old uncle Tom inherited a piece of land from his great-great-uncle. Originally, the property had been in th 阅读详情

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 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)
 

Source
 

Recommend
LL   |   We have carefully selected several similar problems for you:   1281  1528  1498  1533  1532 
 

二分匹配,建边的依据是枚举所有可行的点,然后枚举周围四个方向;输出方案依据mark数组


#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
const int maxn = 10010;  
struct node  
{  
    int to;  
    int next;  
}edge[4 * maxn];  

int vis[maxn];
int head[maxn];  
int mark[maxn];  
bool used[maxn];  
bool mat[110][110];  
int cnt[110][110];  
int tot;  
int n, m;  
int index;  
  
void addedge(int from, int to)  
{  
    edge[tot].to = to;  
    edge[tot].next = head[from];  
    head[from] = tot++;   
}  
  
bool dfs(int x)  
{  
    for (int i = head[x]; i != -1; i = edge[i].next)  
    {  
        if (!used[edge[i].to])  
        {  
            used[edge[i].to] = 1;  
            if (mark[edge[i].to] == -1 || dfs(mark[edge[i].to]))  
            {  
                mark[edge[i].to] = x;
                return true;  
            }  
        }  
    }  
    return false;  
}  
  
int hungary()  
{  
    memset(mark, -1, sizeof(mark));  
    int ans = 0;  
    for (int i = 0; i < index; i++)  
    {  
        memset(used, 0, sizeof(used));  
        if (dfs(i))  
            ans++;  
    }  
    return ans;  
}  
  
int main()  
{  
    int k;  
    while (~scanf("%d%d", &n, &m))  
    {  
    	if (!n && !m)
    	{
    		break;
    	}
    	scanf("%d", &k);
    	map<int, int>qu;
    	qu.clear();
        memset(head, -1, sizeof(head));  
        memset(mat, false, sizeof(mat)); 
        memset(vis, -1, sizeof(vis));
        tot=0;  
        int x, y;  
        for (int i = 0; i < k; i++)  
        {  
            scanf("%d%d", &x, &y);  
            x--;  
            y--; 
            mat[x][y] = true;  
        }  
        index = 0;  
        for (int i = 0; i < n; i++)  
            for (int j = 0; j < m; j++)  
                if (!mat[i][j])  
                {
                	cnt[i][j] = index++; 
                	qu[index - 1] = i * m + j;
                }
                     
        for (int i = 0; i < n; i++)  
            for (int j = 0; j < m; j++)  
            {   
                if (!mat[i][j])  
                {  
                    if (i > 0 && !mat[i - 1][j])  
                        addedge(cnt[i][j], cnt[i - 1][j]);  
                    if (i < n-1 && !mat[i + 1][j])  
                        addedge(cnt[i][j], cnt[i + 1][j]);  
                    if (j > 0 && !mat[i][j - 1])  
                        addedge(cnt[i][j], cnt[i][j - 1]);  
                    if (j < m - 1 && !mat[i][j + 1])  
                        addedge(cnt[i][j], cnt[i][j + 1]);  
                }  
            }  
        int res = hungary();  
        printf("%d\n", res / 2);
        for (int i = 0; i < index; ++i)
        {
        	if (mark[i] != -1)
        	{
        		int a = qu[i];
        		int b = qu[mark[i]];
        		int x1 = a / m + 1;
        		int y1 = a % m + 1;
        		int x2 = b / m + 1;
        		int y2 = b % m + 1;
        		if (vis[a] == -1 && vis[b] == -1)
        		{
        			printf("(%d,%d)--(%d,%d)\n", x1, y1, x2, y2);
        			vis[a] = b;
        			vis[b] = a;
        		}
        	}
        }
        printf("\n");
    }  
    return 0;  
} 


基于MediaPipe的智能俯卧撑计数与姿势矫正系统 在现代健身和体能训练中,俯卧撑是最基础也是最有效的自重训练动作之一。然而,许多人在进行俯卧撑训练时常常存在姿势不正确、计数不准确等问题。本文将介绍如何利用计算机视觉和姿态估计技术,开发一个智能的俯卧撑计数与姿势矫正系统。 阅读详情

相关推荐

219页华为供应链管理:市场预测S&OP计划、销售预测与存货管理精要

S&OP计划的整合作用:S&OP是一种综合的销售和运营计划流程,它将市场预测、生产能力、库存水平和财务目标整合在一起,以确保企业能够平衡供需,实现最佳的运营效率。持续监控与改进:市场预测、S&OP计划、计划委员会的决策以及存货管理都需要持续的监控和评估。供应链策略与执行:华为ISC拥有清晰的供应链策略,并通过SISC架构实现了策略的有效执行,包括供应链网络设计、库存管理、物流优化等。持续的供应链创新:华为ISC不断探索新的供应链管理方法和技术,如数字化供应链、智能物流等,以适应全球化和市场的快速变化。

zuoan1993的博客 2445

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...

weixin_33860147的博客 169

Halcon实战:基于图像清晰度自动筛选最佳对焦图片

本文详细介绍了如何使用Halcon实现基于图像清晰度的自动筛选最佳对焦图片技术。通过分析灰度值统计和标准差等核心指标,结合实战代码示例,帮助开发者高效处理工业检测中的对焦问题,提升自动化检测的准确性和效率。

weixin_27015733的博客 448

HDU 1507(Uncle Tom's Inherited Land*)

二分图的最大匹配问题。 每个格子的横坐标和纵坐标之和为奇数或偶数,和为奇数的格子只可能与和为偶数的格子相邻,所以将和为奇数的格子作为二分图的一边,将和为偶数的格子作为二分图的另一边,如果两个空地格子相邻,则在两者之间连线。然后计算二分图的最大匹配数即可。 #include <cstdio> #include <cstring> #include <cmath&g...

Intelligence1028的博客 229

Vue集成天地图:从定位到交互绘图的完整实践指南

本文详细介绍了如何在Vue项目中集成天地图API,从基础配置到高级功能实现,包括定位、标点、画线等交互绘图功能。通过实战代码示例和性能优化技巧,帮助开发者快速掌握Vue与天地图的结合应用,提升地图开发效率。

weixin_29013129的博客 251

如何用zemax导入solidworks装配体

在zemax使用中,常常需要导入各种零件。如果光机结构较为复杂,那么手工一个一个加载零件,还需要在zmx文件中调整object的位置,非常麻烦。如果能将solidworks的装配体模型直接导入,则可以大幅减小工作量。具体过程为(非序列模式下): 1、新建或打开一个zemax空文件 2、在元件编辑器中,找到一个空文件,双击或直接展开三角符,在类型中找到zemax里的solidworks装配体,如图。...

wojiaoyyy的博客 1万+

HDU1607--二分图最大匹配

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 d

SCUT_Pein 876

239号资源-simulink仿真:MATLAB/Simulink教程(PDF文档)-----已提供下载资源

电网论文源程序擅长文章解读,论文与完整源程序,等方面的知识,电网论文源程序关注python,机器学习,计算机视觉,深度学习,神经网络,数据挖掘领域.电网论文源程序擅长文章解读,论文与完整源程序,等方面的知识,电网论文源程序关注python,机器学习,计算机视觉,深度学习,神经网络,数据挖掘领域.《《《《《《《《更多资源还请持续关注本专栏》》》》》》》《《《《《《《《更多资源还请持续关注本专栏》》》》》》》论文与完整源程序_电网论文源程序的博客-CSDN博客。电网论文源程序-CSDN博客。

LIANG674027206的博客 1090

Uncle Tom's Inherited Land(HDU-1507)

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-...

Alex_McAvoy的博客 821

高精度导航 | RTK:2025年高精度导航算法综述,包括:原理,数据,公式,完整代码,开源代码链接

中国科学院国家授时中心的最新研究表明,PPP-AR/PPP-RTK增强算法使时间传递链路的稳定性提升超过30%,模糊度固定成功率高达93.57%,首次固定时间缩短至20分钟内。当这一愿景实现,人类社会的生产效率和资源利用率将迎来革命性提升,高精度定位将成为像电力、互联网一样的基础服务,深刻重塑我们的生活方式和文明形态。PPP-RTK作为GNSS定位领域的最前沿技术,成功融合了精密单点定位(PPP)和实时动态定位(RTK)的双重优势。,实现在无GNSS信号环境下(如隧道、地下停车场)的连续厘米级定位。

尘世冰封的专栏 1628

【教程4>第5章>第28节】基于帧同步+相位同步+位同步的QPSK调制解调通信系统整体性能分析

综上所述:1.SNR<10db时,整体性能下降,当SNR=0db时,系统无法正常工作。2.gardner环性能达到2.5e-5时偏可以正常工作,增加之后无法正常工作。3.当相位偏差大于pi/4的时候,对最后的性能会有一定影响。

FPGA/MATLAB学习教程/源码/项目合作开发 565

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

无线通信技术及其在机器人中的应用

本文系统阐述了无线通信技术在机器人领域的应用框架与技术选型。首先构建了无线通信的三层理论架构:物理层解决信号传输问题,链路层处理接入控制,网络层实现组网管理。随后详细分析了主流无线技术的特性与适用场景:BLE适用于低功耗传感器节点,Wi-Fi适合高带宽视频传输,5G专网满足工业AGV的广域覆盖需求,星闪技术凭借20μs超低时延和4096台并发连接能力,为高端机器人应用提供突破性解决方案。通过鄂尔多斯隆基5G专网等典型案例,验证了5G在工业AGV规模化部署中的优势,并展望了通感算智融合、星闪+5G协同等未来发

weiyvyy的博客 1124

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

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

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

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

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

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

hdu 1507 Uncle Tom's Inherited Land*

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

uuuuuu 480

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Hdu 1507 Uncle Tom's Inherited Land*

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 题意:给一个N*M的矩阵,一个格子表示一块土地,有些土地被改造成了池塘,问现在如果要按1X2的矩形卖掉土地,最多能卖多少块,并输出方案(任一)。 解法:因为是1X2 的矩阵,所以可以用二分图做最大匹配来做,构图时可以将矩阵按行列和的奇偶进行染色,要保证二部图的建立。 代码: //Hdu

我是一颗小星星~ 802

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

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
上一篇: hdu1548——A strange lift
下一篇: POJ1308——Is It A Tree?
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值