poj 2226 Muddy Fields

Day 4
然后今天是马神~~,讲了第三遍【?】的图论,然后是网络流,再然后是输的分治【【这个完全不会写】】

啊啊啊然后这是一道 最小覆盖的题。

原题:
poj 2226
orspoj【但是多组数据

题意:
在一块N*M上,有一些格子是泥泞的,现在要用一些宽为1的木板把泥地盖住,并且不能盖住好地。木板可以重叠。问最少需要多少木板?

分析:
其实是 完!全!没!有!思路的。No Idea!!
然后听马神大大的~~:

不能盖住好地,那么宽为1的木板只能放在行、列的联通块对应左、右部的中的点,泥地对应边。

所以【【其实这个所以我也没看出来】】:
求二分图最小覆盖就是答案。。

Code:

#include<cstdio>
#include<algorithm>
#include<cstring>
//by clever mars_ch 
using namespace std;
int n,m,nu,nu2,ans;
char map[51][51];
int numr[51][51],nump[51][51],match[2501],used[2501];
int map2[2501][2501];
void number()  //make a number,then if there is a public point,then match an edge; 
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(map[i][j]=='*')
            {
                if(map[i][j-1]=='*') numr[i][j]=numr[i][j-1];
                else numr[i][j]=++nu;
                if(map[i-1][j]=='*') nump[i][j]=nump[i-1][j];
                else nump[i][j]=++nu2;
                map2[numr[i][j]][nump[i][j]]=1;
            }
        }
    }
}
bool find(int x)
{
    for(int i=1;i<=nu2;i++)    // scan every sister[[haha 
    {
        if(used[i] == 0 && map2[x][i])
        {
            used[i]=1;
            if(match[i] == -1 || find(match[i]))   // no  
            {
                match[i]=x;
                return 1;
            }
        }
    }
    return 0; 
}
void hungary()
{
    for(int i=1;i<=n*m;i++)           
    {
        memset(used,0,sizeof(used));
        if(find(i)) ans++;
    }
}
int main()
{
    char jy;
    scanf("%d%d\n",&n,&m);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(j == m)  scanf("%c%c",&map[i][j],&jy);
            else scanf("%c",&map[i][j]);
        }
    }
    number();
    memset(match,-1,sizeof(match));
    hungary();
    printf("%d",ans);
}

//附赠一组查错数据!!!!
/*
3 3
***
*.*
***
*/
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值