Time Limit: 1000MS      Memory Limit: 65536K
Total Submissions: 11490 Accepted: 4270
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 USACO 2005 January Gold

二分图的精华大概就是这样的构图思想了,以行、列为左右部点,连续的*为点构图,求最小点覆盖即可。

真的很神奇。

//Stay foolish,stay hungry,stay young,stay simple
#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; const int MAXN=10005; char mp[MAXN][MAXN];
bool used[MAXN];
int match[MAXN]; int n,m; struct Edge{
int next,to;
}e[MAXN];
int ecnt,head[MAXN];
inline void add(int x,int y){
e[++ecnt].next = head[x];
e[ecnt].to = y;
head[x]=ecnt;
}
bool hungary(int x)
{
for(int i=head[x];i;i=e[i].next)
{
int v = e[i].to;
if(!used[v])
{
used[v] = true;
if(match[v]<0||hungary(match[v]))
{
match[v]=x;
return true;
}
}
}
return false;
}
int dfs()
{
int ret=0;
memset(match,-1,sizeof(match));
for(int i = 1;i <=n*m;i++)
{
memset(used,false,sizeof(used));
if(hungary(i)) ret++;
}
return ret;
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(head,0,sizeof(head));
ecnt=0;
for(int i=1;i<=n;i++)
scanf("%s",mp[i]+1);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(mp[i][j] == '*')
{
int x = i,y = j;
while(x > 1 && mp[x-1][j] == '*') x--;
while(y > 1 && mp[i][y-1] == '*') y--;
add((x-1)*m+j,i*m+(y-1)+n*m);
}
}
}
printf("%d\n",dfs());
}
return 0;
}

[POJ] 2223 Muddy Fields的更多相关文章

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

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

  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 (转化成二分图的最小覆盖)

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

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

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

  5. POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)

    题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...

  6. [POJ] 2226 Muddy Fields(二分图最小点覆盖)

    题目地址:http://poj.org/problem?id=2226 二分图的题目关键在于建图.因为“*”的地方只有两种木板覆盖方式:水平或竖直,所以运用这种方式进行二分.首先按行排列,算出每个&q ...

  7. poj 2226 Muddy Fields(最小点覆盖+巧妙构图)

      Description Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= ...

  8. poj 2226 Muddy Fields(水二分图)

    Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= R <= 50, 1 ...

  9. POJ 2226 Muddy Fields(最小点覆盖)题解

    题意:一片r*c的地,有些地方是泥地,需要铺地板.这些地板宽1,长无限,但只能铺在泥地上不能压到其他地方,问你铺满所有泥地最少几块 思路:我们把一行中连续的泥地看成整体,并把所有横的整体里的点编成一个 ...

随机推荐

  1. poj1661【DP,左右两端dp】

    /* [过滤这一段~~~] 一开始想的[错误的,为自己的总结的写的,读者略过]: 每个状态的点肯定是高度,那么我DP每一层,这样的话就有一层循环,其实这无关复杂度,不会很多时间 错误的是想法是从最高层 ...

  2. A. Banana (2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛)

    题目大意是有一堆猴子,然后每个猴子都有自己喜欢的香蕉类型,然后香蕉会在指定的位置,问每个猴子能不能在每个地方吃到自己喜欢的香蕉. 其实直接暴力即可(因为最大最大最大是50) 上代码: #include ...

  3. 关于协程:nodejs和golang协程的不同

    nodejs和golang都是支持协程的,从表现上来看,nodejs对于协程的支持在于async/await,golang对协程的支持在于goroutine.关于协程的话题,简单来说,可以看作是非抢占 ...

  4. 第02课 操作系统及Linux 系统介绍

    1.操作系统介绍 操作系统(Operating System,简称OS),是计算机系统中必不可少的基础系统软件,它是应用程序运行以及用户操作必备的基础环境支撑,是计算机系统的核心. 操作系统的作用是管 ...

  5. azkaban-web-start.sh启动时出现Table 'execution_flows' is marked as crashed and should be repaired Query错误的解决办法(图文详解)

    问题详情 [hadoop@master bin]$ ./azkaban-web-start.sh Using Hadoop Using Hive from /home/hadoop/app/hive ...

  6. bootstrap div 固定

    div固定在顶部样式: .navbar-fixed-top div固定在底部样式 .navbar-fixed-bottom

  7. js去掉数组的空字符串

    后台返回数据的时候,有些数据为空时,一般都不进行显示,需要去除空字符串. 基本思路:获取数组张度,遍历数组,当数组某个值等于‘’或null或数据类型为undefined时,根据splice方法去除数据 ...

  8. 刷ID卡的就餐系统

    需求分析:公司旧的考勤系统,缺 “就餐”功能模块,不能查询和统计每天的就餐人数.故需开发一个简易的“刷ID卡的就餐系统”,三 部 分组成,一部分为人事资料的增删改查,二部分为处理从“刷卡就餐机”采集的 ...

  9. poj1190 生日蛋糕

    题意: 要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱.当i < M时,要求Ri > ...

  10. vs 2015 编译cocos2dx 报错

    VS 2015 compiling cocos2d-x 3.3 error “fatal error C1189: #error: Macro definition of snprintf confl ...