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.

样例输入

  1. 2
  2. 1 5 3
  3. 0.2 1.5
  4. 0.3 4.8
  5. 0.4 3.5
  6. 4 4 8
  7. 0.7 0.5
  8. 1.7 0.5
  9. 2.8 1.5
  10. 3.7 0.5
  11. 2.2 3.6
  12. 2.7 2.7
  13. 1.2 2.2
  14. 1.2 2.7

样例输出

  1. 1
  2. 3
    【分析】给出一个矩形的长和宽,现有一些光线,其宽度为1,边界都在整数处,然后给出一些点的坐标,
    都为小数。问最少需要多少光线可以将所有点覆盖住。
    很容易想到最小点覆盖集,对于建图,可以看每个点所在的横坐标纵坐标(向上取整),然后连边,
    再用最小点覆盖集模板。最小点覆盖集==最大匹配数。
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <string>
  7. #include <map>
  8. #include <queue>
  9. #include <vector>
  10. #define inf 0x7fffffff
  11. #define met(a,b) memset(a,b,sizeof a)
  12. typedef long long ll;
  13. using namespace std;
  14. const int N = ;
  15. const int M = ;
  16. int read() {
  17. int x=,f=;
  18. char c=getchar();
  19. while(c<''||c>'') {
  20. if(c=='-')f=-;
  21. c=getchar();
  22. }
  23. while(c>=''&&c<='') {
  24. x=x*+c-'';
  25. c=getchar();
  26. }
  27. return x*f;
  28. }
  29. int n1,n2,k;
  30. int mp[N][N],vis[N],link[N];
  31. int dfs(int x) {
  32. for(int i=; i<=n2; i++) {
  33. if(mp[x][i]&&!vis[i]) {
  34. vis[i]=;
  35. if(link[i]==-||dfs(link[i])) {
  36. link[i]=x;
  37. return ;
  38. }
  39. }
  40. }
  41. return ;
  42. }
  43.  
  44. int main()
  45. {
  46. int cas ;
  47. scanf("%d\n",&cas);
  48. while(cas--) {
  49. int s=;
  50. scanf("%d%d%d",&n1,&n2,&k);
  51. met(mp,);
  52. double x,y;
  53. for(int i=; i<k; i++) {
  54. scanf("%lf%lf",&x,&y);
  55. int xx=int(x)+;
  56. int yy=int(y)+;
  57. mp[xx][yy]=;
  58. }
  59. memset(link,-,sizeof(link));
  60. for(int i=; i<=n1; i++) {
  61. memset(vis,,sizeof(vis));
  62. if(dfs(i)) s++;
  63. }
  64. printf("%d\n",s);
  65. }
  66. return ;
  67. }

Jewelry Exhibition(最小点覆盖集)的更多相关文章

  1. ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)

    //匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...

  2. POJ2226 Muddy Fields(二分图最小点覆盖集)

    题目给张R×C的地图,地图上*表示泥地..表示草地,问最少要几块宽1长任意木板才能盖住所有泥地,木板可以重合但不能盖住草地. 把所有行和列连续的泥地(可以放一块木板铺满的)看作点且行和列连续泥地分别作 ...

  3. POJ1325 Machine Schedule(二分图最小点覆盖集)

    最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...

  4. POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)

    题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...

  5. POJ 3041 Asteroids (最小点覆盖集)

    题意 给出一个N*N的矩阵,有些格子上有障碍,要求每次消除一行或者一列的障碍,最少消除多少次可以全部清除障碍. 思路 把关键点取出来:一个障碍至少需要被它的行或者列中的一个消除. 也许是最近在做二分图 ...

  6. hdu 1054(最小点覆盖集)

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. 二分图变种之最小路径覆盖、最小点覆盖集【poj3041】【poj2060】

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=54859604 向大(hei)佬(e)势力学(di ...

  8. POJ 3041 Asteroids (二分图最小点覆盖集)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24789   Accepted: 13439 Descr ...

  9. hdu 1498(最小点覆盖集)

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. 房子里的K2 BPM业务流程管理

    房…子这件事上,尴尬实在太多. ಥ_ಥ 职场新人,租房很尴尬: 未婚男女,婚房很尴尬: 有下一代的,学区房很尴尬: 耄耋之年,养老房很尴尬... ▽ 甭管买房.租房.装修.设计,关于房子的尴尬事,三天 ...

  2. Python应用与实践

    http://www.cnblogs.com/skynet/archive/2013/05/06/3063245.html

  3. Yslow&PageSpeed– 诊断各种缓慢症状

    Google的PageSpeed和yahoo的yslow是各位不可少的前端工具(同样也都是firebug的插件,安装了firebug之后才可以拥有她们),当各位无法用三寸不烂之舌收拾产品和各种大佬的时 ...

  4. pyqt5 笔记(三)py2exe 实现代码打包exe

    python3.4 安装64位的版本 py2exe 下载地址: https://pypi.python.org/pypi/py2exe/0.9.2.0#downloads cmd——>进入pyf ...

  5. 使用开源工具MonoDevelop开发GTK#图形界面

    转自:http://developer.51cto.com/art/201011/235040.htm Mono一直到现在的2.8已经完全可以胜任一些比较小的项目了,但相关的开发文档与教程一直比较匮乏 ...

  6. 2016-1-9 Quartz框架的学习,剪裁图片并设置边框

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  7. BZOJ 3224 普通平衡树

    这个是第一份完整的treap代码.嗯...虽然抄的百度的版,但还是不错的. !bzoj上不能用srand. #include<iostream>#include<cstdio> ...

  8. Python OpenCV —— Border

    关于border的部分,边缘处理. # -*- coding: utf-8 -*- """ Created on Wed Sep 28 00:58:51 2016 @au ...

  9. 【Tsinghua OJ】循环移位(Cycle)

    Description Cycle shifting refers to following operation on the sting. Moving first letter to the en ...

  10. Codeforces Round #365 (Div. 2)-D Mishka and Interesting sum(树状数组)

    题目链接:http://codeforces.com/contest/703/problem/D 思路:看了神犇的代码写的... 偶数个相同的数异或结果为0,所以区间ans[l , r]=区间[l , ...