zoukankan      html  css  js  c++  java
  • BZOJ1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场

    1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场

    Time Limit: 5 Sec  Memory Limit: 64 MB
    Submit: 310  Solved: 183
    [Submit][Status][Discuss]

    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.

        大雨侵袭了奶牛们的牧场.牧场是一个R * C的矩形,其中1≤R,C≤50.大雨将没有长草的土地弄得泥泞不堪,可是小心的奶牛们不想在吃草的时候弄脏她们的蹄子.  为了防止她们的蹄子被弄脏, 约翰决定在泥泞的牧场里放置一些木板.每一块木板的宽度为1个单位,长度任意.每一个板必须放置在平行于牧场的泥地里.    约翰想使用最少的木板覆盖 所有的泥地.一个木板可以重叠在另一个木板上,但是不能放在草地上.

    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.

     1行:两个整数RC.

     2R+1行:每行C个字符,其中“*’代表泥地,“.”代表草地.

    Output

    * Line 1: A single integer representing the number of boards FJ needs.

       最少需要多少木板.

    Sample Input

    4 4
    *.*.
    .***
    ***.
    ..*.

    Sample Output

    4

    HINT

     

    Source

     
    【题解】
    分别给横着的、竖着的连通块标号,分别是X集和Y集
    每一个泥泞块是连接X集某连通块和Y集某连通块的一条边,
    求最小点覆盖即可
    被空间卡了一个WA一个RE。。莫名其妙,明明开到50了啊
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <algorithm>
     6 
     7 inline void read(int &x)
     8 {
     9     x = 0;char ch = getchar(), c = ch;
    10     while(ch < '0' || ch > '9')c = ch, ch - getchar();
    11     while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
    12     if(c == '-')x = -x;
    13 }
    14  
    15 const int MAXN = 1000 + 10;
    16 
    17 char gg[MAXN][MAXN];
    18 
    19 int lk[MAXN], b[MAXN], n, m, g[MAXN][MAXN], row[MAXN][MAXN], line[MAXN][MAXN], r, c;
    20 
    21 int dfs(int u)
    22 {
    23     for(register int v = 1;v <= m;++ v)
    24     {
    25         if(g[u][v] && !b[v])
    26         {
    27             b[v] = 1;
    28             if(lk[v] == -1 || dfs(lk[v]))
    29             {
    30                 lk[v] = u;
    31                 return 1;
    32             }
    33         }
    34     }
    35     return 0;
    36 }
    37 
    38 int xiongyali()
    39 {
    40     int ans = 0;
    41     memset(lk, -1, sizeof(lk));
    42     for(register int i = 1;i <= n;++ i)
    43     {
    44         memset(b, 0, sizeof(b));
    45         ans += dfs(i);
    46     }
    47     return ans;
    48 }
    49 
    50 int main()
    51 {
    52     read(r), read(c);
    53     for(register int i = 1;i <= r;++ i)
    54         scanf("%s", gg[i] + 1);
    55     register int tot = 0;
    56     for(register int i = 1;i <= r;++ i)
    57         for(register int j = 1;j <= c;++ j)
    58             if(gg[i][j] == '*')
    59             {
    60                 ++ tot;
    61                 while(gg[i][j] == '*' && j <= c)row[i][j] = tot, ++ j;
    62             }
    63     n = tot;
    64     tot = 0;
    65     for(register int j = 1;j <= c;++ j)
    66         for(register int i = 1;i <= r;++ i)
    67             if(gg[i][j] == '*')
    68             {
    69                 ++ tot;
    70                 while(gg[i][j] == '*' && i <= r)line[i][j] = tot, ++ i;
    71             }
    72     m = tot;
    73     for(register int i = 1;i <= r;++ i)
    74         for(register int j = 1 ;j <= c;++ j)
    75             if(gg[i][j] == '*')
    76                 g[row[i][j]][line[i][j]] = 1;
    77     printf("%d", xiongyali());
    78     return 0;
    79 }
    BZOJ1735
     
  • 相关阅读:
    ArcGIS10.1的安装问题
    谁是农业信息化的第一推动力
    名片
    【旺铺2012分享】导航CSS代码使用修改技巧!
    新旺铺教程之导航12
    新旺铺教程之导航
    Photoshop制作通透的紫色宝石字
    用PS怎么画虚线圆?
    一张彩色图片,如何用Photoshop处理成一张轮廓图(就是变成刚用铅笔画出来时的那样)_...
    php从入门到放弃系列-01.php环境的搭建
  • 原文地址:https://www.cnblogs.com/huibixiaoxing/p/7566654.html
Copyright © 2011-2022 走看看