zoukankan      html  css  js  c++  java
  • Jewelry Exhibition(最小点覆盖集)

    Jewelry Exhibition

    时间限制: 1 Sec  内存限制: 64 MB
    提交: 3  解决: 3
    [提交][状态][讨论版]

    题目描述

    To guard the art jewelry exhibition at night, the security agency has decided to use a new laser beam system, consisting of sender-receiver pairs. Each pair generates a strip of light of one unit width and guards all objects located inside the strip. Your task is to help the agency and to compute for each exhibition room the minimum number of sender-receiver pairs which are sufficient to protect all exhibits inside the room.
    Any room has a rectangle shape, so we describe it as an [0, N] × [0, M] rectangle in the plane. The objects we need to guard are represented as points inside that rectangle. Each sender is mounted on a wall and the corresponding receiver on the opposite wall in such a way that the generated strip is a rectangle of unit width and length either N or M. Since the new laser beam system is still not perfect, each sender-receiver pair can only be mounted to generate strips the corners of which have integer coordinates. An additional drawback is that the sender-receiver pairs can protect only
    items inside the strips, but not those lying on their borders. Thus, the security agency arranged the exhibits in such a way that both coordinates of any point representing an exhibit are non-integers.
    The figure below (left) illustrates eight items arranged in [0, 4] × [0, 4] (the second sample input). In the room, up to eight sender-receiver pairs can be mounted. The figure to the right shows an area protected by three sender-receiver pairs.

    输入

    The input starts with the number of exhibition rooms R ≤ 10. Then the descriptions of the R rooms follow. A single description starts with a single line, containing three integers: 0 < N ≤ 100, 0 < M ≤ 100, specifying the size of the current room and 0 < K ≤ 104, for the number of exhibits.
    Next K lines follow, each of which consists of two real numbers x, y describing the exhibit coordinates.
    You can assume that 0 < x < N, 0 < y < M and that x and y are non-integer.

    输出

    For every room output one line containing one integer, that is the minimum number of sender-receiver pairs sufficient to protect all exhibits inside the room.

    样例输入

    2
    1 5 3
    0.2 1.5
    0.3 4.8
    0.4 3.5
    4 4 8
    0.7 0.5
    1.7 0.5
    2.8 1.5
    3.7 0.5
    2.2 3.6
    2.7 2.7
    1.2 2.2
    1.2 2.7
    

    样例输出

    1
    3
    【分析】给出一个矩形的长和宽,现有一些光线,其宽度为1,边界都在整数处,然后给出一些点的坐标,
    都为小数。问最少需要多少光线可以将所有点覆盖住。

    很容易想到最小点覆盖集,对于建图,可以看每个点所在的横坐标纵坐标(向上取整),然后连边,
    再用最小点覆盖集模板。最小点覆盖集==最大匹配数。
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <string>
    #include <map>
    #include <queue>
    #include <vector>
    #define inf 0x7fffffff
    #define met(a,b) memset(a,b,sizeof a)
    typedef long long ll;
    using namespace std;
    const int N = 1005;
    const int M = 24005;
    int read() {
        int x=0,f=1;
        char c=getchar();
        while(c<'0'||c>'9') {
            if(c=='-')f=-1;
            c=getchar();
        }
        while(c>='0'&&c<='9') {
            x=x*10+c-'0';
            c=getchar();
        }
        return x*f;
    }
    int n1,n2,k;
    int mp[N][N],vis[N],link[N];
    int dfs(int x) {
        for(int i=1; i<=n2; i++) {
            if(mp[x][i]&&!vis[i]) {
                vis[i]=1;
                if(link[i]==-1||dfs(link[i])) {
                    link[i]=x;
                    return 1;
                }
            }
        }
        return 0;
    }
    
    int main()
    {
        int cas ;
        scanf("%d
    ",&cas);
        while(cas--) {
            int s=0;
            scanf("%d%d%d",&n1,&n2,&k);
            met(mp,0);
            double x,y;
            for(int i=0; i<k; i++) {
                scanf("%lf%lf",&x,&y);
                int xx=int(x)+1;
                int yy=int(y)+1;
                mp[xx][yy]=1;
            }
            memset(link,-1,sizeof(link));
            for(int i=1; i<=n1; i++) {
                memset(vis,0,sizeof(vis));
                if(dfs(i)) s++;
            }
            printf("%d
    ",s);
        }
        return 0;
    }
  • 相关阅读:
    忘记的知识点补充
    mysql使用过程中出现的问题总结
    身份证校验
    数据库plsql配置
    前端字符间间距与单词间间距
    Oracle中的instr()函数 详解及应用
    Oracle执行过程中出现的问题
    572. Subtree of Another Tree 大树里包括小树
    404. Sum of Left Leaves 左叶子之和
    637. Average of Levels in Binary Tree 二叉树的层次遍历再求均值
  • 原文地址:https://www.cnblogs.com/jianrenfang/p/5934908.html
Copyright © 2011-2022 走看看