集训队专题(6)1005 Uncle Tom's Inherited Land*

本题探讨如何在一块包含多个池塘的矩形土地上,利用1x2的矩形地块进行分割,以达到最大化可售地块数量的目的。文章提供了完整的代码实现,并详细解释了如何通过构建二分图并使用匈牙利算法来解决问题。

Uncle Tom's Inherited Land*

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2908    Accepted Submission(s): 1206
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
 

和大多数二分图的题相似,题目并不是难在求出最大匹配上,而是建立二分图,此题的问题是让我们求出最多的一种用1*2的矩形填涂的方法,也就是说在建立的时候我们要以相邻的作为两个集合,所以我们将相间的格子作为一个集合,不难发现相间的格子横纵坐标之和的奇偶性是一样的,所以在代码实现上我们把横纵坐标之和奇偶行相等的作为一个集合来建图。

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
const int MAXN = 510;
int uN,vN,g[MAXN][MAXN],linker[MAXN];
bool used[MAXN];
bool dfs(int u)
{
    for(int v = 0; v < vN;v++)
        if(g[u][v] && !used[v])
        {
            used[v] = true;
            if(linker[v] == -1 || dfs(linker[v]))
            {
                linker[v] = u;
                return true;
            }
        }
    return false;
}
int hungary()
{
    int res = 0;
    memset(linker,-1,sizeof(linker));
    for(int u = 0;u < uN;u++)
    {
        memset(used,false,sizeof(used));
        if(dfs(u))res++;
    }
    return res;
}
int a[110][110];
int b[100];
int main()
{
    int n,m,k;
    int u,v;
    while(scanf("%d%d",&n,&m)==2)
    {
        if(n == 0 && m == 0)break;
        scanf("%d",&k);

        memset(a,0,sizeof(a));
        while(k--)
        {
            scanf("%d%d",&u,&v);
            u--;v--;
            a[u][v] = -1;
        }
        int index = 0;
        for(int i = 0;i < n;i++)
            for(int j = 0;j < m;j++)
                if(a[i][j]!=-1)
                {
                    b[index] = i*m + j;
                    a[i][j] = index++;
                }
        uN = vN = index;
        memset(g,0,sizeof(g));
        for(int i = 0;i < n;i++)
            for(int j= 0;j < m;j++)
                if(a[i][j]!=-1 && (i+j)%2==1)
                {
                    u = a[i][j];
                    if(i > 0 && a[i-1][j]!=-1)
                        g[u][a[i-1][j]]=1;
                    if(i < n-1 && a[i+1][j]!=-1)
                        g[u][a[i+1][j]]=1;
                    if(j > 0 && a[i][j-1]!=-1)
                        g[u][a[i][j-1]]=1;
                    if(j < m-1 && a[i][j+1]!=-1)
                        g[u][a[i][j+1]]=1;
                }
        int ans = hungary();
        printf("%d\n",ans);
        for(int i = 0;i <vN;i++)
            if(linker[i]!=-1)
            {
                int x1 = b[i]/m;
                int y1 = b[i]%m;
                int x2 = b[linker[i]]/m;
                int y2 = b[linker[i]]%m;
                printf("(%d,%d)--(%d,%d)\n",x1+1,y1+1,x2+1,y2+1);
            }
        printf("\n");
    }
    return 0;
}


内容概要:本文是一份针对2025年中国企业品牌传播环境撰写的《全网媒体发稿白皮书》,聚焦企业媒体发稿的策略制定、渠道选择与效果评估难题。通过分析当前企业面临的资源分散、内容同质、效果难量化等核心痛点,系统性地介绍了新闻媒体、央媒、地方官媒和自媒体四大渠道的特点与适用场景,并深度融合“传声港”AI驱动的新媒体平台能力,提出“策略+工具+落地”的一体化解决方案。白皮书详细阐述了传声港在资源整合、AI智能匹配、舆情监测、合规审核及全链路效果追踪方面的技术优势,构建了涵盖曝光、互动、转化与品牌影响力的多维评估体系,并通过快消、科技、零售等行业的实战案例验证其有效性。最后,提出了按企业发展阶段和营销节点定制的媒体组合策略,强调本土化传播与政府关系协同的重要性,助力企业实现品牌声量与实际转化的双重增长。; 适合人群:企业市场部负责人、品牌方管理者、公关传播从业者及从事数字营销的相关人员,尤其适用于初创期至成熟期不同发展阶段的企业决策者。; 使用场景及目标:①帮助企业科学制定媒体发稿策略,优化预算分配;②解决渠道对接繁琐、投放不精准、效果不可衡量等问题;③指导企业在重大营销节点(如春节、双11)开展高效传播;④提升品牌权威性、区域渗透力与危机应对能力; 阅读建议:建议结合自身企业所处阶段和发展目标,参考文中提供的“传声港服务组合”与“预算分配建议”进行策略匹配,同时重视AI工具在投放、监测与优化中的实际应用,定期复盘数据以实现持续迭代。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值