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. 微信H5支付:网络环境未能通过安全验证,请稍后再试。解决办法(PHP版)

    前(tu)言(cao) (这段前言纯属吐槽,着急解决问题的小伙伴,赶紧看正文吧) 最近做了支付宝和微信支付,先做的是PC端网站的支付,就是出个二维码,然后手机扫描支付,当然支付宝在扫码页面支持登录支付 ...

  2. beanshell postprocessor解决编码

    beanshell postprocessor  String s=new String(prev.getResponseData(),"UTF-8");        char  ...

  3. ORACLE SEQUENCE的简单介绍

    先假设有这么一个表: create table S_Depart ( DepartId INT not null, DepartName NVARCHAR2() not null, DepartOrd ...

  4. spring cloud+docker 简单说一说

    spring boot 微服务开发工具 spring cloud 微服务框架治理工具集 这么做: 1.搭建spring cloud 基础组件(服务发现,服务注册,服务配置,监控,追踪,API网关) 以 ...

  5. Python输入输出练习,运算练习,turtle初步练习

    Hello World! 简单交互(交互式,文件式)教材P19 radius=25 area=3.1415*radius*radius print(area) print('{:.2f}'.forma ...

  6. IOS学习【xcode 7新特性url链接】

    由于xcode7的更新,在访问http链接的时候会输出错误信息 The resource could not be loaded because the App Transport Security ...

  7. 利用 VMWare 搭建随机拓扑网络

    这篇文章是计算机网络上机实验课的作业. 实验任务:利用 VMWare 搭建一个由 5 个主机组成的随机拓扑的网络.要求该网络中至少有 2 个子网,两个路由器 .实验的网络拓扑图如下: 网络中有两个路由 ...

  8. web服务的三大主流架构

    1.远程过程调用 2.服务导向架构 3.表述性状态转移 今天在自学Spring架构时貌似发现 rest的表现.与RPC方式的最大差别,SOA方式更加关注如何去连接服务而不是去特定某个实现的细节.而re ...

  9. Eclipse安装完findbugs插件后,SVN插件不可用有关问题解决

    Eclipse安装完findbugs插件后,SVN插件不可用问题解决: 安装findbugs插件后,SVN插件就消失了.后来从网上查到解决方案:eclipse/configuration目录下的org ...

  10. 201521123024 《Java程序设计》第1周学习总结

    一.本周章学习总结 1.Java的版本迁移 2.运用eclipse和notepad++编写Java 3.对JDK,JRE,JVM有初步的了解 二.书面作业 1.为什么java程序可以跨平台运行?执行j ...