您的位置:首页 > 其它

poj 2226 Muddy Fields

2016-05-02 19:54 281 查看
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
***
*.*
***
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  poj