• poj 2226(最小点覆盖集)


    嘛。。稍微有一点变形,相当于每隔一段草,一行或一列就成新的了,用rnum,cnum记录一下就好了。

    # include <cstdio>
    # include <cstring>
    # include <algorithm>
    # include <iostream>
    using namespace std;
    char map[100][100];
    int mp[500][500],f[500],flag[500],r,c,sum,rnum,cnum,maxn,col[100][100];
    int find(int i)
    {
        int j;
        for (j=1;j<=cnum;++j)
        {
            if (mp[i][j]&&!flag[j])
            {
                flag[j] = 1;
                if (!f[j]||find(f[j]))
                {
                    f[j] = i;
                    return 1;
                }
            }
        }
        return 0;
    }
    int main()
    {
        int i,j;
        char str[100];
        while (~scanf("%d%d",&r,&c))
        {
            sum = 0;rnum = 1;cnum = c;
            memset(mp,0,sizeof(mp));
            memset(f,0,sizeof(f));
            for (i=1;i<=r;++i)
            {
                scanf("%s",str+1);
                for (j=1;j<=c;++j)
                {
                    map[i][j] = str[j];
                    if (str[j]=='*')
                    {
                        if (map[i][j-1] == '.')
                            ++rnum;
                        if (i==1)
                            col[i][j] = j;
                        else if (map[i-1][j] == '.')
                            col[i][j] = (++cnum);
                        else
                            col[i][j] = col[i-1][j];
                        mp[rnum][col[i][j]] = 1;
                    }
                }
                rnum++;
            }
            for (i=1;i<=rnum;++i)
            {
                memset(flag,0,sizeof(flag));
                sum += find(i);
            }
            printf("%d\n",sum);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    7z usecaes
    最新状态
    ABAP 常用FUNCTION (最近工作中用到的)
    又是一个星期五
    阿牛
    自我定位的重要性
    smortform 创建
    换个角度想或许不一样
    为什么喜欢跟男生聊天小小分析
    BDC 代码设置
  • 原文地址:https://www.cnblogs.com/1carus/p/3339878.html
Copyright © 2020-2023  润新知