来源poj2226

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

Hint

OUTPUT DETAILS:

Boards 1, 2, 3 and 4 are placed as follows:

1.2.
.333
444.
..2.

Board 2 overlaps boards 3 and 4.

有点像小行星,但是它值能覆盖连续的泥池,所以要构图,将横着放的板子和纵放的板子编号,然后连起来算最小点覆盖

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1017;
int pre[N];
int visit[N],line[N][N],line1[N][N],line2[N][N];
char Map[N][N];
int n,m,y,x;
int cas,cas1;
bool find(int x)
{
rep(i,1,cas1+1)
{
if(line[x][i]&&visit[i]==0)
{
visit[i]=1;
if(pre[i]==0||find(pre[i]))
{
pre[i]=x;
return true;
}
}
}
return false;
}
void deal()
{
cas=0;
rep(i,1,n+1)
{
rep(j,1,m+1)
{
if(Map[i][j]=='*')
{
cas++;
while(j<=m&&Map[i][j]=='*')
{
line1[i][j]=cas;
j++;
}
}
}
}
cas1=0;
rep(j,1,m+1)
{
rep(i,1,n+1)
{
if(Map[i][j]=='*')
{
cas1++;
while(i<=n&&Map[i][j]=='*')
{
line2[i][j]=cas1;
i++;
}
}
}
}
rep(i,1,n+1)
rep(j,1,m+1)
if(Map[i][j]=='*')
line[line1[i][j]][line2[i][j]]=1;
}
int main()
{
while(~sf("%d%d",&n,&m))
{
mm(Map,'0');
mm(line,0);
mm(line2,0);
mm(line1,0);
mm(pre,0);
for(int i = 1; i <=n; i++)
{
for(int j = 1; j <= m; j++)
{
cin>>Map[i][j];
}
}
deal();
int ans=0;
rep(i,1,cas+1)
{
mm(visit,0);
if(find(i))
ans++;
}
pf("%d\n",ans);
}
return 0;
}

O - 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. Muddy Fields

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

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

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

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

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

  7. poj Muddy Fields

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

  8. BNUOJ 2345 Muddy Fields

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

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

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

  10. POJ2226 Muddy Fields

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

随机推荐

  1. hbase.client.keyvalue.maxsize的默认值

    hbase的列族的最大值是在hbase配置里的hbase.client.keyvalue.maxsize,默认大小为10M,即 10485760 . http://eclecl1314-163-com ...

  2. .Net转Java.05.为啥MySQL没有nolock

    今天忽然想到一个问题,原来为了提高SQL Server性能,公司规定查询语句一般都要加 WITH (NOLOCK)的 现在转Java了,用了MySQL为啥不提这个事情了? 先在MySQL里写了一个查询 ...

  3. 通过Pdf预览Excel或者word或者Powerpoint (C#将Office转换为PDF)

    下面代码是Excel转换为PDF using System; using System.Collections.Generic; using System.Linq; using System.Web ...

  4. iOS:练习题中如何用技术去实现一个连线题

    一.介绍 本人做的app涉及的是教育行业,所以关于练习题的开发肯定是家常便饭.例如,选择题.填空题.连线题.判断题等,每一种题型都需要技术去实现,没啥多大难度,这里呢,就给出实现连线题的核心代码吧.过 ...

  5. java socket编程中backlog的含义(zz)

    使用Java.NET.ServerSocket能够方便的创建一个服务端套接字,这个类的构造函数有一个参数backlog.下面这段代码,在本机的8888端口上建立了一个套接字,backlog设置为5. ...

  6. [Canvas]空战游戏进阶 增加己方子弹管理类

    点此下载源码,可用Chrome打开观看. 图例: 代码: <!DOCTYPE html> <html lang="utf-8"> <meta http ...

  7. 【JavaScript 插件】图片展示插件 PhotoSwipe 初识

    前言: 考虑自己网站的图片展示,而且要支持移动端和PC端.自己写的代码也不尽如意,要写好的话也需要时间,于是就想到了使用相关插件. 准备: PhotoSwipe 官网地址:http://photosw ...

  8. HTTPS之acme.sh申请证书

    1.关于let's encrypt和acme.sh的简介 1.1 let's encrypt Let's Encrypt是一个于2015年三季度推出的数字证书认证机构,旨在以自动化流程消除手动创建和安 ...

  9. yarn 切换 设置 镜像 源

    1.查看一下当前源 yarn config get registry 2.切换为淘宝源 yarn config set registry https://registry.npm.taobao.org ...

  10. RobotFrameWork编写接口测试及如何断言

    1. 前言 本篇是第一系列(Http接口自动化)的第五课程,如果对系列课程大纲不清楚的,可以查看<RobotFramework系列免费课程-开课了~>. 前面我们介绍了,在真正实施前,需先 ...