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. Codeforces - 1081C - Colorful Bricks - 简单dp - 组合数学

    https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1 ...

  2. 二分匹配ZOJ3646

    //题意:类比线代里:把矩阵中的U看作[1],是否满足一个满秩矩阵 //利用二分匹配就是 //每一行都有相对应的列: #include<iostream> #include<stri ...

  3. 拓扑排序复习——Chemist

    一.基本算法 拓扑序列:对于一张有向图,求一个序列ai若对于每一条边(u,v),都满足au<=av ,则称这个序列为这张有向图的拓扑序列,一张图可能有多个拓扑序列. 求拓扑序列:找到入度为0的点 ...

  4. python操作pymongo

    import pymongo from bson import ObjectId mongo_client = pymongo.MongoClient(host="127.0.0.1&quo ...

  5. UWP 动画

    一:StoryBoard 一般翻译成演示图版或者故事板,就像电影中的情节串联板,它是一个动画时间线的容器. 二:动画的分类       简单动画:以Animation结尾,例如DoubleAnimat ...

  6. 143 Reorder List 重排链表

    给定一个单链表L:L0→L1→…→Ln-1→Ln,重新排列后为: L0→Ln→L1→Ln-1→L2→Ln-2→…必须在不改变节点的值的情况下进行原地操作.例如,给定链表 {1,2,3,4},按要求重排 ...

  7. 74LVC2G241双缓冲3态驱动器

  8. ES--在windows上快速安装

    环境准备 java环境部署: Java下载路径:http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a ...

  9. apache http server2.2 + tomcat5.5 性能调优

    httpd加tomcat做负载均衡,采用session复制方式共享session,采用http-proxy连接方式,打开status mod 一.没有做httpd和tomcat的启动参数修改,包括jv ...

  10. IIS6配置FastCGI遇到ERROR5的解决方法

    FastCGI Error The FastCGI Handler was unable to process the request. ------------------------------- ...