Radar Installation

原文是English,直接上中文

Descriptions:

假定海岸线是无限长的直线。陆地位于海岸线的一侧,海洋位于另一侧。每个小岛是位于海洋中的一个点。对于任何一个雷达的安装 (均位于海岸线上),只能覆盖 d 距离,因此海洋中的小岛被雷达安装所覆盖的条件是两者间的距离不超过 d 。

我们使用卡笛尔坐标系,将海岸线定义为 x 轴。海洋的一侧位于 x 轴上方,陆地的一侧位于下方。给定海洋中每个小岛的位置,并给定雷达安装的覆盖距离,您的任务是写一个程序,找出雷达安装的最少数量,使得所有的小岛都被覆盖。注意:小岛的位置以它的 x-y 坐标表示。

图 A: 雷达安装的示例输入

Input

输入由多个测试用例组成。每个测试用例的第一行,包含了两个整数 n (1<=n<=1000) 和 d,其中 n 是海洋中小岛的数目,d 是雷达安装的覆盖距离。接下来是 n 行,每行包含了两个整数,表示每个小岛的坐标。每组测试用例之间,以一个空行间隔。

Output

对于每个测试用例,输出一行,包括测试用例的编号,以及雷达安装所需的最小数量。"-1" 个安装,表示该测试用例无解决方案。

Sample Input

  1. 3 2
  2. 1 2
  3. -3 1
  4. 2 1
  5.  
  6. 1 2
  7. 0 2
  8.  
  9. 0 0

Sample Output

  1. Case 1: 2
  2. Case 2: 1

题目链接:

https://vjudge.net/problem/OpenJ_Bailian-1328

雷达必须在x轴的[s[i].left,s[i].right]之间,每个小岛都有对应在x轴的点是s[i].left和s[i].right,问题转换成用最少的点,使所有的线段都被覆盖到

AC代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <fstream>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <deque>
  7. #include <vector>
  8. #include <queue>
  9. #include <string>
  10. #include <cstring>
  11. #include <map>
  12. #include <stack>
  13. #include <set>
  14. #include <sstream>
  15. #define mod 1000000007
  16. #define eps 1e-6
  17. #define ll long long
  18. #define INF 0x3f3f3f3f
  19. #define ME0(x) memset(x,0,sizeof(x))
  20. using namespace std;
  21. struct point
  22. {
  23. double left,right;//线段两端
  24. bool operator<(const point &c)const//按做端点排序
  25. {
  26. return left<c.left;
  27. }
  28. };
  29. point points[];
  30. int n,d;
  31. int sum=;
  32. int f=;
  33. //求每个Case
  34. int solve()
  35. {
  36. int ans=;//雷达个数
  37. double nowpos;
  38. sort(points,points+n);
  39. // for(int i=0; i<n; i++)
  40. // cout<<points[i].left<<" "<<points[i].right<<endl;
  41. nowpos=points[].right;
  42. for(int i=; i<n; ++i)
  43. {
  44. // cout<<"*"<<endl;
  45. if(points[i].left<=nowpos)
  46. nowpos=min(nowpos,points[i].right);
  47. else//若当前线段与目前线段没有交集,则加入新雷达
  48. {
  49. ++ans;
  50. nowpos=points[i].right;
  51. }
  52. }
  53. return ans;
  54. }
  55. int main()
  56. {
  57. while(cin>>n>>d,n+d)
  58. {
  59. f=;
  60. sum++;
  61. int x,y;
  62. for(int i=; i<n; ++i)
  63. {
  64. cin>>x>>y;
  65. if(y>d)
  66. f=;
  67. else
  68. {
  69. double t=d*d-y*y;
  70. points[i].left=x-sqrt(t);
  71. points[i].right=x+sqrt(t);
  72. }
  73. }
  74. if(f)
  75. printf("Case %d: %d\n",sum,solve());
  76. else
  77. printf("Case %d: -1\n",sum);
  78. }
  79. }

【OpenJ_Bailian - 1328】Radar Installation (贪心)的更多相关文章

  1. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  2. poj 1328 Radar Installation(贪心+快排)

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  3. POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)

    Input The input consists of several test cases. The first line of each case contains two integers n ...

  4. POJ 1328 Radar Installation 贪心算法

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  5. POJ 1328 Radar Installation 贪心 难度:1

    http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...

  6. poj 1328 Radar Installation(贪心)

    题目:http://poj.org/problem?id=1328   题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...

  7. POJ 1328 Radar Installation 贪心题解

    本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...

  8. POJ 1328 Radar Installation#贪心(坐标几何题)

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...

  9. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

  10. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

随机推荐

  1. VLC RTP Over TCP

    在RTSP协议请求数据时,让VLC以TCP的方式获取服务器发来的RTP数据 不为别的,下次回复直接用博客链接就能回复大家了! 操作:工具 -> 首选项 然后: 搞定! ------------- ...

  2. docker: docker安装和镜像下载

    1 安装docker的apt源 apt-get install apt-transport-https ca-certificates curl software-properties-common ...

  3. dij+堆优化

    写这个dij+堆优化的原因是有些地方卡SPFA,只能搞这个: 香甜的奶油: #include<iostream> #include<cstdio> #include<cs ...

  4. 双端队列篇deque SDUT OJ 双向队列

    双向队列 Time Limit: 1000MS Memory limit: 65536K 题目描述 想想双向链表……双向队列的定义差不多,也就是说一个队列的队尾同时也是队首:两头都可以做出队,入队的操 ...

  5. poj3461 Oulipo —— KMP

    题目链接:http://poj.org/problem?id=3461 代码如下: #include<cstdio>//poj 3461 kmp #include<cstring&g ...

  6. 使用jQuery集成Google翻译

    利用jQuery,轻松将google翻译集成到你的web应用中. 1. [代码][JavaScript]代码     ​1<script src="Scripts/Translator ...

  7. java的一个爬虫

    进行抓取页面,我看了一下人家的教程,一般要用到htmlparser用来解析html得到一个网页的相关链接,用httpclient抓取网页数据, 下面是一我写的spider类 package com.o ...

  8. 关于“C++语言程序设计”书的一个类

    class book{    char* title;    int num_pages;    int cur_page;public:    book(const char* theTitle, ...

  9. BZOJ_4026_dC Loves Number Theory _主席树+欧拉函数

    BZOJ_4026_dC Loves Number Theory _主席树+欧拉函数 Description  dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯 竭 ...

  10. jquery的跨域请求

    项目中关于ajax jsonp的使用,出现了问题:可以成功获得请求结果,但没有执行success方法总算搞定了,记录一下 function TestAjax() {    $.ajax({       ...