Radar Installation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 54593   Accepted: 12292

Description

Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the
sea can be covered by a radius installation, if the distance between them is at most d. 



We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write
a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates. 

 

Figure A Sample Input of Radar Installations



Input

The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing
two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases. 



The input is terminated by a line containing pair of zeros 

Output

For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.

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

Source

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <algorithm>
  5.  
  6. #define maxn 1010
  7. using namespace std;
  8.  
  9. struct Node {
  10. double u, v;
  11. friend bool operator<(const Node& a, const Node& b) {
  12. return a.u < b.u;
  13. }
  14. } E[maxn];
  15. int N, D;
  16.  
  17. int main() {
  18. int i, ok, id, ans, cas = 1;
  19. double x, y, d, flag;
  20. while(scanf("%d%d", &N, &D), N) {
  21. printf("Case %d: ", cas++);
  22. ok = 1; id = 0;
  23. for(i = 0; i < N; ++i) {
  24. scanf("%lf%lf", &x, &y);
  25. if(y > D) ok = 0;
  26. if(!ok) continue;
  27. d = sqrt(D * D - y * y);
  28. E[id].u = x - d;
  29. E[id++].v = x + d;
  30. }
  31.  
  32. if(!ok) {
  33. printf("-1\n");
  34. continue;
  35. }
  36.  
  37. sort(E, E + id);
  38.  
  39. flag = E[0].v; ans = 1;
  40. for(i = 1; i < N; ++i) {
  41. if(E[i].u <= flag) {
  42. if(E[i].v <= flag) flag = E[i].v;
  43. continue;
  44. }
  45. ++ans; flag = E[i].v;
  46. }
  47.  
  48. printf("%d\n", ans);
  49. }
  50. return 0;
  51. }

POJ1328 Radar Installation 【贪心&#183;区间选点】的更多相关文章

  1. poj1328 Radar Installation —— 贪心

    题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...

  2. UVALive 2519 Radar Installation 雷达扫描 区间选点问题

    题意:在坐标轴中给出n个岛屿的坐标,以及雷达的扫描距离,要求在y=0线上放尽量少的雷达能够覆盖全部岛屿. 很明显的区间选点问题. 代码: /* * Author: illuz <iilluzen ...

  3. POJ1328 Radar Installation(贪心)

    题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...

  4. [POJ1328]Radar Installation

    [POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...

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

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

  6. POJ--1328 Radar Installation(贪心 排序)

    题目:Radar Installation 对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点 排序之后贪心一下就ok 用cin 好像一直t看 ...

  7. zoj1360/poj1328 Radar Installation(贪心)

    对每个岛屿,能覆盖它的雷达位于线段[x-sqrt(d*d-y*y),x+sqrt(d*d+y*y)],那么把每个岛屿对应的线段求出来后,其实就转化成了经典的贪心法案例:区间选点问题.数轴上有n个闭区间 ...

  8. POJ1328——Radar Installation

    Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...

  9. POJ 1328 Radar Installation 贪心 A

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

随机推荐

  1. hdu 1116(并查集+欧拉路径)

    Play on Words Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. oracle修改字段类型由varchar2修改为clob类型

    oracle修改字段类型由varchar2修改为clob类型 http://blog.sina.com.cn/s/blog_9d12d07f0102vxis.html

  3. [BZOJ1072][SCOI2007]排列perm 状压dp

    1072: [SCOI2007]排列perm Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2488  Solved: 1546[Submit][St ...

  4. bootstrap只有遮罩层没有对话框的解决方法

    前端很差很差,猜测应该是各种js冲突的问题,换了一个jquery或bootstrap版本的不兼容. https://blog.csdn.net/Pabebe/article/details/70230 ...

  5. (10)C#静态方法,静态字段,静态类,匿名类

    6.静态方法 使用静态方法就可不必用类的实例化调用次函数 class Test { public static void method() { ........ } //当调用一个method()时就 ...

  6. 1424 零树 (树形DP)

    1424 零树 题意 给出一棵树,每次可以选择一个包含节点 1 的连通块,将所有的节点的权值同时加 1 或减 1 ,问最少多少次操作使所有节点权值变为 0 . 分析 这种题意简单的题目好处就是能很快知 ...

  7. Delphi制作QQ自动登录器源码

    Delphi制作QQ自动登录器源码  http://www.cnblogs.com/sunsoft/archive/2011/02/25/1964967.html 以TM2009为例,检查了一下,未登 ...

  8. ubuntu14.04安装 chrome

    安装谷歌浏览器,只需要三行代码: 打开终端,输入 cd /tmp 对于谷歌Chrome32位版本,使用如下链接: wget https://dl.google.com/linux/direct/goo ...

  9. vi中使用“/”查找字符

    在vi 文件中使用"/"查找字符串 命令模式下,输入 /word 后回车,即查找word,按 n 查找下一个匹配单词,按 N 查找上一个匹配单词.

  10. python核心编程学习记录之Web编程

    cgi未完待续