Muddy Fields

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= R <= 50, 1 <= C <= 50). While good for the grass, the rain makes some patches of bare earth quite muddy. The cows, being meticulous grazers, don't want to get their hooves dirty while they eat.

To prevent those muddy hooves, Farmer John will place a number of wooden boards over the muddy parts of the cows' field. Each of the boards is 1 unit wide, and can be any length long. Each board must be aligned parallel to one of the sides of the field.

Farmer John wishes to minimize the number of boards needed to cover the muddy spots, some of which might require more than one board to cover. The boards may not cover any grass and deprive the cows of grazing area but they can overlap each other.

Compute the minimum number of boards FJ requires to cover all the mud in the field.

Input

* Line 1: Two space-separated integers: R and C

* Lines 2..R+1: Each line contains a string of C characters, with '*' representing a muddy patch, and '.' representing a grassy patch. No spaces are present.

Output

* Line 1: A single integer representing the number of boards FJ needs.

Sample Input

4 4
*.*.
.***
***.
..*.

Sample Output

4

经典构图
 #include <cstdio>
#include <cmath>
#include <queue>
#include <string.h>
#include <iostream>
using namespace std;
int head[],linkx[],vi[],q[];
int dx[],dy[];
struct Edge
{
int to,next;
Edge() {};
Edge(int t,int n):to(t),next(n) {}
};
Edge a[];
int an=,nn;
void AddEdge(int u,int v)
{
a[an]=Edge(v,head[u]);
head[u]=an++;
}
bool bfs()
{
int i,u,v,h,t;
h=t=;
bool flag=;
memset(dx,-,sizeof(dx));
memset(dy,-,sizeof(dy));
for(i=; i<=nn; i++)
if(!vi[i])
q[h++]=i,dx[i]=;
while(h!=t)
{
u=q[t++];
for(i=head[u]; ~i; i=a[i].next)
{
if(dy[v=a[i].to]==-)
{
dy[v]=dx[u]+;
if(linkx[v]==-)flag=;
else
{
dx[linkx[v]]=dy[v]+;
q[h++]=linkx[v];
}
}
}
}
return flag;
}
bool dfs(int u)
{
int v,i;
for(i=head[u]; ~i; i=a[i].next)
{
v=a[i].to;
if(dy[v]==dx[u]+)
{
dy[v]=-;
if(linkx[v]==-||dfs(linkx[v]))
{
linkx[v]=u;
return ;
}
}
}
return ;
}
int MaxMatch()
{
int ans=;
memset(vi,,sizeof(vi));
while(bfs())
for(int i=; i<=nn; i++)
if(!vi[i]&&dfs(i))
vi[i]=,ans++;
return ans;
}
int main()
{
int i,j,m,n;
int x[][];
while(~scanf("%d%d",&n,&m))
{
memset(head,-,sizeof(head));
memset(linkx,-,sizeof(linkx));
an=;
getchar();
for(i=; i<=n; i++)
{
for(j=; j<=m; j++)
{
x[i][j]=getchar();
}
getchar();
}
int now='';
for(i=; i<=n; i++)
{
j=;
while(j<=m)
{
while(j<=m&&x[i][j]!='*')j++;
while(j<=m&&x[i][j]=='*')x[i][j++]=now;
now++;
}
}
nn=now;
now='';
for(i=; i<=m; i++)
{
j=;
while(j<=n)
{
while(j<=n&&x[j][i]=='.')j++;
while(j<=n&&x[j][i]!='.')AddEdge(now-'',(int)(x[j++][i]-''));
now++;
}
}
printf("%d\n",MaxMatch());
}
}

Muddy Fields的更多相关文章

  1. poj 2226 Muddy Fields(最小覆盖点+构图)

    http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  2. poj 2226 Muddy Fields (转化成二分图的最小覆盖)

    http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  3. POJ 2226 Muddy Fields(最小顶点覆盖)

    POJ 2226 Muddy Fields 题目链接 题意:给定一个图,要求用纸片去覆盖'*'的位置.纸片能够重叠.可是不能放到'.'的位置,为最少须要几个纸片 思路:二分图匹配求最小点覆盖.和放车那 ...

  4. bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖

    链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...

  5. poj 2226 Muddy Fields (二分匹配)

    Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7340   Accepted: 2715 Desc ...

  6. poj Muddy Fields

    Muddy Fields 原题去我创的专题里找,在文件夹首页. 题目: 给出N*M矩阵.当中*表示泥土,.表示小草.要你用最少的木板把泥土覆盖. 木板长度不限.可是仅仅能水平和竖直. 行列式二分匹配配 ...

  7. BNUOJ 2345 Muddy Fields

    Muddy Fields Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original I ...

  8. POJ Muddy Fields 泥泞的牧场 二分图

    Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13235   Accepted: 4879 汪星人 ...

  9. POJ2226 Muddy Fields

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10149   Accepted: 3783 Description Rain ...

随机推荐

  1. grep Pocket Reference读记

    1 简介 grep的基本命令格式如下:           grep [options] [regexp] [filename]   如果regexp中含有空格,应该使用单引号或双引号括起来.单引号和 ...

  2. Bootstrap-table使用记录(转)

    HTML代码 /*index.cshtml*/ @section styles{ <style> .main { margin-top:20px; } .modal-body .form- ...

  3. ElasticSearch和Kibana 5.X集群的安装

    ElasticSearch和Kibana 5.X集群的安装 1.准备工作 1.1.下载安装包 1.2.系统的准备 2.ElasticSearch集群的安装 2.1.修改 config/elastics ...

  4. cobbler实现自动安装

    author:JevonWei 版权声明:原创作品 cobbler 配置目录 配置文件目录 /etc/cobbler /etc/cobbler/settings : cobbler 主配置文件 /et ...

  5. maven 添加memcached.jar配置方法

    针对Java项目添加 memcahced 在mvnrepository 找了半天也没找到memcached.jar的配置xml, 由于目前Javamemcached client没有官方的maven ...

  6. zTree勾选状态的禁用节点不在选中节点里

    问题描述: 由于业务需求,需要将一部分节点设置为选中并且是禁用的状态.设置这部分节点的chkDisabled和checked属性值都为true.在zTree树上这部分节点是选中且禁用的状态,但是在保存 ...

  7. chrome开发工具指南(六)

    检查和编辑页面与样式 使用 Chrome DevTools 的 Elements 面板检查和实时编辑页面的 HTML 与 CSS. 在 Elements 面板中检查和实时编辑 DOM 树中的任何元素. ...

  8. 【笔记】shellcode相关整理

    0x01:shellcode定义 Shellcode实际是一段代码(也可以是填充数据),是用来发送到服务器利用特定漏洞的代码,一般可以获取权限.另外,Shellcode一般是作为数据发送给受攻击服务器 ...

  9. PowerShell: 问题,此系统上禁止运行脚本解决方法

    刚学Django,在PowerShell上建立一个虚拟环境,准备激活,问题来了:    激活的时候报错了,有点儿懵,之前在命令行没问题啊,我又去命令行试了下,果然可以: 感受到了暴击,赶紧上网求助大神 ...

  10. nrm的安装 、定义和用法

    因为npm包管理工具是属于国外的,所以在中国使用它下载东西的时候比较慢.这时我们就想用国内的淘宝镜像.也有别的,所以当你想切换下载源的时候就会用到nrm了. ###首先,nrm是什么呢? 开发的npm ...