Muddy Fields
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10961   Accepted: 4071

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

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.

Source

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=;
char mp[N][N];
int used[N*N],head[N*N],tot,n,m;
struct node
{
int to,next;
} e[];
bool vis[N*N];
int aa[N][N],bb[N][N],a,b;
void add(int u,int v)
{
e[tot].to=v;
e[tot].next=head[u];
head[u]=tot++;
}
bool findx(int u)
{
for(int i=head[u]; ~i; i=e[i].next)
{
int v=e[i].to;
if(vis[v]) continue;
vis[v]=;
if(!used[v]||findx(used[v]))
{
used[v]=u;
return true;
}
}
return false;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
int maxmatch=;
tot=;
a=b=;
memset(head,-,sizeof(head));
memset(aa,,sizeof(aa));
memset(bb,,sizeof(bb));
for(int i=; i<=n; ++i) scanf("%s",mp[i]+);
for(int i=; i<=n; ++i) for(int j=; j<=m; ++j)
{
bool c=;
while(mp[i][j]=='*'&&j<=m) c=,aa[i][j++]=a;
if(c) ++a;
}
for(int i=; i<=m; ++i) for(int j=; j<=n; ++j)
{
bool c=;
while(mp[j][i]=='*'&&j<=n) c=,bb[j++][i]=b;
if(c) ++b;
}
for(int i=; i<=n; ++i) for(int j=; j<=m; ++j) if(aa[i][j]) add(aa[i][j],bb[i][j]);
memset(used,,sizeof(used));
for(int i=; i<a; ++i)
{
memset(vis,,sizeof(vis));
if(findx(i)) ++maxmatch;
}
printf("%d\n",maxmatch);
}
}

poj2226更改行列匹配建图的更多相关文章

  1. HDU 3036 Escape 网格图多人逃生 网络流||二分匹配 建图技巧

    题意: 每一个' . '有一个姑娘, E是出口,'.'是空地 , 'X' 是墙. 每秒钟每一个姑娘能够走一步(上下左右) 每秒钟每一个出口仅仅能出去一个人 给定n*m的地图, 时限T 问全部姑娘是否能 ...

  2. TTTTTTTTTTTTTTTTT POJ 2226 草地覆木板 二分匹配 建图

    Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9754   Accepted: 3618 Desc ...

  3. TTTTTTTTTTTTTTTTTT POJ 2724 奶酪消毒机 二分匹配 建图 比较难想

    Purifying Machine Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5004   Accepted: 1444 ...

  4. Antenna Placement POJ - 3020 二分图匹配 匈牙利 拆点建图 最小路径覆盖

    题意:图没什么用  给出一个地图 地图上有 点 一次可以覆盖2个连续 的点( 左右 或者 上下表示连续)问最少几条边可以使得每个点都被覆盖 最小路径覆盖       最小路径覆盖=|G|-最大匹配数 ...

  5. POJ-3020 Antenna Placement---二分图匹配&最小路径覆盖&建图

    题目链接: https://vjudge.net/problem/POJ-3020 题目大意: 一个n*m的方阵 一个雷达可覆盖两个*,一个*可与四周的一个*被覆盖,一个*可被多个雷达覆盖问至少需要多 ...

  6. kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树

    二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...

  7. HDU 1045 Fire Net(行列匹配变形+缩点建图)

    题意:n*n的棋盘上放置房子.同一方同一列不能有两个,除非他们之间被墙隔开,这种话. 把原始图分别按行和列缩点 建图:横竖分区.先看每一列.同一列相连的空地同一时候看成一个点,显然这种区域不可以同一时 ...

  8. (匹配 二维建图) Antenna Placement --POJ --3020

    链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82834#probl ...

  9. Card Game Cheater---hdu1528(扑克建图求二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1528 题意就是给有两个人有n张牌第二个人知道第一个人的牌的序列: 然后第二个人尽可能的让自己得更高的分 ...

随机推荐

  1. MAC攻击及缺陷

    MAC攻击及缺陷 MAC有好几种实现方式 对MAC的攻击 重放攻击 重放攻击的防护 密钥推测攻击 MAC算法的缺陷 第三方证明 防止否认 前面我们在讲HMAC的时候简单讲过了什么是MAC消息认证码. ...

  2. 【Linux常见命令】uname命令

    uname命令用于显示系统信息. uname可显示电脑以及操作系统的相关信息. 语法 uname [-amnrsv][--help][--version] 参数说明: -a或--all 显示全部的信息 ...

  3. composer+psr-4实现自动加载

    自动加载 对于库的自动加载信息,Composer 生成了一个 vendor/autoload.php 文件.你可以简单的引入这个文件,你会得到一个免费的自动加载支持. require 'vendor/ ...

  4. python- 函数高级

    函数高级 一.默认参数 1.默认参数概念 默认参数指函数/方法在定义时为形参赋值,对应的形参称为默认参数. 默认参数是一个参数定义期的概念,与调用无关. 2.默认参数的作用 如果参数定义默认参数,在调 ...

  5. Next.js 7发布,构建速度提升40%

    Next.js团队发布了其开源React框架的7版本.该版本的Next.js主要是改善整体的开发体验,包括启动速度提升57%.开发时的构建速度提升40%.改进错误报告和WebAssembly支持. \ ...

  6. 团队中的 Node.js 具体实践

    前天,我们公司前端团队的几个人一起去大搜车参加了芋头所组织的「搜车 Node Party」.这是我第一次参加与 Node.js 相关的线下聚会,如果不算「杭JS」的话. 聚会现场 这次聚会的主题全部是 ...

  7. C++编程入门题目--No.2

    题目:企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高 于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提 成7.5%:20万到4 ...

  8. Nginx模块开发(4)————使用subrequest访问第三方服务

    该模块可以完成如下的功能,当我们输入http://你的ip/lcw?s_sh000001时,会使用subrequest方式得到新浪服务器上的上证指数,代码如下: //start from the ve ...

  9. docker overlay network

    下载binary consul wget https://releases.hashicorp.com/consul/1.2.2/consul_1.2.2_linux_amd64.zip unzip ...

  10. Neo4j填坑记录-Neo4jClient建立节点、建立关系相关

    最近一个项目需要用到知识图谱,选用了neo4j图数据库,在这过程中遇到几个坑,记录一下 1.无法登录,疯狂提示“WebSocket connection failure. Due to securit ...