Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12565   Accepted: 4651

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

  1. 4 4
  2. *.*.
  3. .***
  4. ***.
  5. ..*.

Sample Output

  1. 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.

 
 
 
 
 
 
代码:
  1. //F - Muddy Fields POJ - 2226
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdio>
  5. #include<algorithm>
  6. #include<cmath>
  7. using namespace std;
  8. const int maxn=;
  9. const int N=maxn*maxn/;
  10. int G[N][N],vis[N],link[N];
  11. int n;
  12. bool Find(int u){
  13. for(int i=;i<=n;i++){
  14. if(G[u][i]&&!vis[i]){
  15. vis[i]=;
  16. if(link[i]==-||Find(link[i])){
  17. link[i]=u;
  18. return true;
  19. }
  20. }
  21. }
  22. return false;
  23. }
  24. int solve(){
  25. int cnt=;
  26. memset(link,-,sizeof(link));
  27. for(int i=;i<=n;i++){
  28. memset(vis,,sizeof(vis));
  29. if(Find(i))cnt++;
  30. }
  31. return cnt;
  32. }
  33. char mat[maxn][maxn];
  34. int vis1[maxn][maxn],vis2[maxn][maxn];
  35. int main(){
  36. int m;
  37. for(int i=;i<=;i++)
  38. mat[][i]=mat[i][]='.';
  39. while(~scanf("%d%d",&n,&m)){
  40. for(int i=;i<=n;i++){
  41. for(int j=;j<=m;j++)
  42. cin>>mat[i][j];
  43. }
  44. int tot1=,tot2=;
  45. memset(vis1,,sizeof(vis1));
  46. memset(vis2,,sizeof(vis2));
  47. for(int i=;i<=n;i++){
  48. for(int j=;j<=m;j++){
  49. if(mat[i][j]=='*'){
  50. if(!vis1[i][j-])vis1[i][j]=tot1++;
  51. else vis1[i][j]=vis1[i][j-];
  52. if(!vis2[i-][j])vis2[i][j]=tot2++;
  53. else vis2[i][j]=vis2[i-][j];
  54. }
  55. }
  56. }
  57. memset(G,,sizeof(G));
  58. for(int i=;i<=n;i++){
  59. for(int j=;j<=m;j++){
  60. if(mat[i][j]=='*')
  61. G[vis1[i][j]][vis2[i][j]]=;
  62. }
  63. }
  64. n=max(tot1,tot2);
  65. printf("%d\n",solve());
  66. }
  67. return ;
  68. }

POJ 2226.Muddy Fields-二分图最大匹配(最小点覆盖)的更多相关文章

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

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

  2. poj 2226 Muddy Fields (二分图)

    大意:给定n*m网格, 每个格子为泥地或草地, 可以用一些长度任意宽度为1的木板盖住泥地, 要求不能盖到草地, 求最少要多少块木板能盖住所有泥地. 最小点覆盖板子题, 建图跑最大匹配即可. #incl ...

  3. POJ 2226 Muddy Fields 二分图(难点在于建图)

    题意:给定一个矩阵和它的N行M列,其中有一些地方有水,现在有一些长度任意,宽为1的木板,要求在板不跨越草,用一些木板盖住这些有水的地方,问至少需要几块板子? 思路:首先想到如果没有不准跨越草的条件则跟 ...

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

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

  5. poj 2226 Muddy Fields(最小点覆盖)

    题意: M*N的矩阵,每个格不是*就是#.     *代表水坑,#代表草地. 农民要每次可以用一块宽为1,长不限的木板去铺这个矩阵.要求这块木板不能覆盖草地.木板可以重复覆盖(即一块木板与另一块木板有 ...

  6. poj 2226 Muddy Fields (转化成二分图的最小覆盖)

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

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

    *.*. .*** ***. ..*. 题意:有一个N*M的像素图,现在问最少能用几块1*k的木条覆盖所有的 * 点,k为>=1的任意值. 分析:和小行星那题很像.小行星那题是将一整行(列)看作 ...

  8. poj 2226 Muddy Fields(最小覆盖点+构图)

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

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

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

随机推荐

  1. Pytest框架介绍

    Pytest框架介绍.安装 pytest是python测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,功能更强大 pytest特征 1:断言提示信 ...

  2. Python字符串的常用操作学习

    >>> name = "I love my job!" >>> name.capitalize() #首字母大写 'I love my job! ...

  3. 孤荷凌寒自学python第十三天python代码的外部模块引用与基本赋值语句

    孤荷凌寒自学python第十三天python代码的外部模块引用与基本赋值语句 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 从结构化编程流行以来,代码便被分块存储,称之为模块或库. 在pyt ...

  4. CMake Tutorial & Example

    Tutorial CMakeLists用于告诉CMake我们要对这个目录下的文件做什么事情 cmake 的特点主要有: 1,开放源代码,使用类 BSD 许可发布.http://cmake.org/HT ...

  5. 机器学习框架Tensorflow数字识别MNIST

    SoftMax回归  http://ufldl.stanford.edu/wiki/index.php/Softmax%E5%9B%9E%E5%BD%92 我们的训练集由  个已标记的样本构成: ,其 ...

  6. VS调试时不捕捉Exception

    在方法上添加 [DebuggerHidden] 这样,发生错误的时候,VS就不会捕捉到这个错误,否则,会在错误的地方中断. [DebuggerHidden] public void DeleteAll ...

  7. ajax是可以本地运行的

    ajax是可以本地运行的,经过验证,可以是可以,但跟浏览器有关,火狐和新IE可以,chrome不可以,旧ie不知道什么原因也不可以.但是浏览器也有它的安全策略,必须是同一目录下的文件可以访问.chro ...

  8. vue cli & vue 3.x

    vue cli & vue 3.x https://cli.vuejs.org/dev-guide/ui-api.html#ui-api https://cli.vuejs.org/zh/gu ...

  9. java链接数据库--Mysql

    /************************************************************************* > File Name: Mysql.jav ...

  10. AtCoder keyence2019 E Connecting Cities

    keyence2019_e $N$ 个节点的无向图 $G$,节点 $i,j$ 之间的边权值为 $|i - j| \times D + A_i + A_j$ . 求最小生成树(Minimum Spann ...