Jewelry Exhibition(最小点覆盖集)

时间:2021-04-12 23:08:45

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.
Jewelry Exhibition(最小点覆盖集)

输入

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 = ;
const int M = ;
int read() {
int x=,f=;
char c=getchar();
while(c<''||c>'') {
if(c=='-')f=-;
c=getchar();
}
while(c>=''&&c<='') {
x=x*+c-'';
c=getchar();
}
return x*f;
}
int n1,n2,k;
int mp[N][N],vis[N],link[N];
int dfs(int x) {
for(int i=; i<=n2; i++) {
if(mp[x][i]&&!vis[i]) {
vis[i]=;
if(link[i]==-||dfs(link[i])) {
link[i]=x;
return ;
}
}
}
return ;
} int main()
{
int cas ;
scanf("%d\n",&cas);
while(cas--) {
int s=;
scanf("%d%d%d",&n1,&n2,&k);
met(mp,);
double x,y;
for(int i=; i<k; i++) {
scanf("%lf%lf",&x,&y);
int xx=int(x)+;
int yy=int(y)+;
mp[xx][yy]=;
}
memset(link,-,sizeof(link));
for(int i=; i<=n1; i++) {
memset(vis,,sizeof(vis));
if(dfs(i)) s++;
}
printf("%d\n",s);
}
return ;
}