Jewelry Exhibition(最小点覆盖集)
Jewelry Exhibition
时间限制: 1 Sec 内存限制: 64 MB
提交: 3 解决: 3
[提交][状态][讨论版]
题目描述
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.

输入
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.
输出
样例输入
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 ;
}
Jewelry Exhibition(最小点覆盖集)的更多相关文章
- ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)
//匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...
- POJ2226 Muddy Fields(二分图最小点覆盖集)
题目给张R×C的地图,地图上*表示泥地..表示草地,问最少要几块宽1长任意木板才能盖住所有泥地,木板可以重合但不能盖住草地. 把所有行和列连续的泥地(可以放一块木板铺满的)看作点且行和列连续泥地分别作 ...
- POJ1325 Machine Schedule(二分图最小点覆盖集)
最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...
- POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)
题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...
- POJ 3041 Asteroids (最小点覆盖集)
题意 给出一个N*N的矩阵,有些格子上有障碍,要求每次消除一行或者一列的障碍,最少消除多少次可以全部清除障碍. 思路 把关键点取出来:一个障碍至少需要被它的行或者列中的一个消除. 也许是最近在做二分图 ...
- hdu 1054(最小点覆盖集)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 二分图变种之最小路径覆盖、最小点覆盖集【poj3041】【poj2060】
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=54859604 向大(hei)佬(e)势力学(di ...
- POJ 3041 Asteroids (二分图最小点覆盖集)
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24789 Accepted: 13439 Descr ...
- hdu 1498(最小点覆盖集)
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- C++中两块内存重叠的string的copy方法
如果两段内存重叠,用memcpy函数可能会导致行为未定义. 而memmove函数能够避免这种问题,下面是一种实现方式: #include <iostream> using namespac ...
- Matlab与C/C++联合编程之Matlab以MEX方式调用C/C++代码(二)
如果我有一个用C语言写的函数,实现了一个功能,如一个简单的函数: double add(double x, double y) { return x + y; } 现在我想要在Matlab中使用它,比 ...
- 一个完整的ansible实施目录示例
当前目录:
- (转)ASP.NET(C#) 读取EXCEL ——另加解决日期问题
使用OLEDB可以对excel文件进行读取,我们只要把该excel文件作为数据源即可. 一 在D盘创建excel文件test.xls: 二 将工作表Sheet1的内容读取到DataSet string ...
- 去掉NavigationBar底部的黑线
UINavigationBar *navigationBar = self.navigationController.navigationBar; [navigationBar setBackgr ...
- eclipse中导入一个android工程有The import android cannot be resolved错误怎么办
解决方法: 右键工程→Bulid Path→Configure Build Path... 选择Android,如图,在Project Build Target里面勾选相应的SDK即可 右键工程,pr ...
- php大力力 [033节] 随便看看:PHP程序员学习C++
php大力力 [033节] 随便看看:PHP程序员学习C++ 2014 兄弟连高洛峰 PHP教程14.1.7 在PHP脚本中操作MySQL数据库4 观看 - 56.com http://www.med ...
- 实现:编辑短信,按power键锁屏后,再点亮屏幕,进入的还是编辑短信界面,按返回键才会进入解锁界面。
描述:在编辑短信界面按电源键锁屏后,重新按电源键点亮屏幕,并没有进入到锁屏界面而是在编辑短信界面,此时短信界面悬浮与锁屏界面之上,这时按返回键关闭编辑短信界面,回到锁屏界面,是如何实现的呢,只需要在需 ...
- JAVA的数组和输入
package com.java1995; import java.util.Scanner; public class Array { public static void main(String[ ...
- Reason we use Camel
Camel is mainly for integration purpose, in our project we also use it inside the single component t ...