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. 1 2
  6. 0 2
  7. 0 0

Sample Output

  1. Case 1: 2
  2. Case 2: 1
    题意:假定海岸线是无限长的直线。陆地位于海岸线的一侧,海洋位于另一侧。每个小岛是位于海洋中的一个点。对于任何一个雷达的安装 (均位于海岸线上),只能覆盖 d 距离,因此海洋中的小岛被雷达安装所覆盖的条件是两者间的距离不超过 d  
    我们使用卡笛尔坐标系,将海岸线定义为 x 轴。海洋的一侧位于 x 轴上方,陆地的一侧位于下方。给定海洋中每个小岛的位置,并给定雷达安装的覆盖距离,您的任务是写一个程序,找出雷达安装的最少数量,使得所有的小岛都被覆盖。注意:小岛的位置以它的 x-y 坐标表示。
  3. 题解:这道题乍一看没有思路,但是如果不从雷达考虑,从小岛考虑,那么每个小岛都有一个对应的覆盖区间,只有区间内的点才能覆盖这个岛,所以问题变成了区间选点
    只是要注意,精度是double
  4. 代码:
  1. #include<cmath>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<iostream>
  5. #include<algorithm>
  6. using namespace std;
  7. struct node
  8. {
  9. double l,r;
  10. } a[];
  11. int x[],y[];
  12. int n,d,cnt,t=;
  13. bool cmp(node a,node b)
  14. {
  15. return a.l<b.l;
  16. }
  17. int main()
  18. {
  19. while(scanf("%d%d",&n,&d)!=EOF&&n)
  20. {
  21. t++;
  22. int flag=;
  23. cnt=;
  24. if(d<=)
  25. {
  26. flag=;
  27. }
  28. for(int i=; i<=n; i++)
  29. {
  30. scanf("%d%d",&x[i],&y[i]);
  31. if(y[i]>d||y[i]<)
  32. {
  33. flag=;
  34. }
  35. double dr=sqrt((double)d*d-y[i]*y[i]);
  36. a[i].l=x[i]-dr;
  37. a[i].r=x[i]+dr;
  38. }
  39. if(flag==)
  40. {
  41. printf("Case %d: -1\n",t);
  42. continue;
  43. }
  44. sort(a+,a+n+,cmp);
  45. double lim=a[].r;
  46. for(int i=; i<=n; i++)
  47. {
  48. if(a[i].l>lim)
  49. {
  50. lim=a[i].r;
  51. cnt++;
  52. }
  53. else
  54. {
  55. if(a[i].r<lim)
  56. {
  57. lim=a[i].r;
  58. }
  59. }
  60. }
  61. printf("Case %d: %d\n",t,cnt);
  62. }
  63. }

POJ - 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 贪心算法

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

  4. poj 1328 Radar Installation(贪心)

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

  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 贪心题解

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

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

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

  8. 贪心 POJ 1328 Radar Installation

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

  9. POJ 1328 Radar Installation 【贪心 区间选点】

    解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...

随机推荐

  1. 第14篇 PSR-3规范(日志)

    1. Specification 1.1 Basics The LoggerInterface exposes eight methods to write logs to the eight RFC ...

  2. 对于global的介绍

    抄自http://veniceweb.googlecode.com/svn/trunk/public/daily_tech_doc/erlang_global_20091109.txt 1. 介绍:这 ...

  3. zufeoj 分数线划定

    分数线划定 时间限制: 1 Sec  内存限制: 128 MB提交: 13  解决: 7[提交][状态][讨论版] 题目描述 世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,A ...

  4. JavaWeb---总结(十九)Session机制

    一.术语session session,中文经常翻译为会话,其本来的含义是指有始有终的一系列动作/消息,比如打电话时从拿起电话拨号到挂断电话这中间的一系列过程可以称之为一个session.有时候我们可 ...

  5. PHP 简单实现webSocket

    费话少说,用源代码说话 1)客户端实现 1 <html> 2 <head> 3 <meta charset="UTF-8"> 4 <tit ...

  6. 0003-程序流程1之app.js

    index.html中引入各种依赖的文件 由ng-app处开始angular Js的管理 angular.module('App', ['']) .run(function($rootScope,.. ...

  7. 什么是Ajax和JSON,它们的优缺点

    什么是Ajax??? 术语Ajax用来描述一组技术,它使浏览器可以为用户提供更为自然的浏览体验. Ajax它是“Asynchronous JavaScript + XML的简写” 定义Ajax: Aj ...

  8. js中的Array

    js中的Array 啥是ArrayLike对象 类似,下面这种对象的就是ArrayLike var arraylike = { 0: "a", 1: "b", ...

  9. Deep Learning 学习笔记(1):线性回归( Linear Regression )

    关于DL,由于我是零经验入门, 事实上我是从最简单的ML开始学起, 所以这个系列我也从ML开始讲起. ===============并行分割线================= 一.线性回归 线性回归 ...

  10. fiddler代理hosts配置

    1 需求背景 fidder开启后,C:\Windows\System32\drivers\etc\hosts配置失效问题:fiddler本身代理hosts配置表,修改后,可以省去在手机等代理使用者的系 ...