Radar Installation

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.

                                                                         

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

3 2
1 2
-3 1
2 1 1 2
0 2 0 0

Sample Output

Case 1: 2
Case 2: 1
题目大意:x轴上可以放置雷达(放置位置可为小数),以放置位置为圆心,d为半径做圆来覆盖岛屿,输出最小的雷达数以覆盖所有的岛屿。无法覆盖输出-1。
解题思路:假设某个岛屿的坐标为(x,y),则在(x-sqrt(d*d-y*y),x+sqrt(d*d-y*y))范围内的雷达可以覆盖到此岛屿。
     先求出各个岛屿的可覆盖雷达范围,在根据其区间左端点进行排序,再通过贪心确定需要的最少雷达数。
     ps:当一个岛屿的纵坐标大于d时,不可能覆盖到,输出-1。
     ps2:进行贪心时,设置一个变量tmpr=p[1].r。
当p[i].r<tmpr时,tmpr=p[i].r 否则p[i]点会漏掉。
当p[i].l>tmpr是,tmpr=p[i].r,cnt++
Code:
 #include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct point
{
double x,y;
double l,r;
} p[];
bool cmp(struct point a,struct point b)
{
return a.l<b.l;
}
int main()
{
double m,d,tmpr;
int i,n,ok,cnt,times=;
while (scanf("%d %lf",&n,&d)!=EOF)
{
times++;
ok=;
if (n==&&d==) break;
for (i=; i<=n; i++)
{
scanf("%lf %lf",&p[i].x,&p[i].y);
if (p[i].y>d) ok=;
p[i].l=p[i].x-sqrt(d*d-p[i].y*p[i].y);
p[i].r=p[i].x+sqrt(d*d-p[i].y*p[i].y);
}
if (ok)
{
sort(p+,p+n+,cmp);
tmpr=p[].r;
cnt=;
for (i=; i<=n; i++)
{
if (p[i].l>tmpr) tmpr=p[i].r,cnt++;
if (p[i].r<tmpr) tmpr=p[i].r;
}
printf("Case %d: %d\n",times,cnt);
}
else printf("Case %d: -1\n",times);
}
return ;
}

POJ1328——Radar Installation的更多相关文章

  1. [POJ1328]Radar Installation

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

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

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

  3. POJ1328 Radar Installation 【贪心&#183;区间选点】

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

  4. POJ1328 Radar Installation 解题报告

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

  5. poj1328 Radar Installation(贪心 策略要选好)

    https://vjudge.net/problem/POJ-1328 贪心策略选错了恐怕就完了吧.. 一开始单纯地把island排序,然后想从左到右不断更新,其实这是错的...因为空中是个圆弧. 后 ...

  6. POJ1328 Radar Installation(贪心)

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

  7. zoj1360/poj1328 Radar Installation(贪心)

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

  8. poj1328 Radar Installation —— 贪心

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

  9. ZOJ-1360 || POJ-1328——Radar Installation

    ZOJ地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=360 POJ地址:http://poj.org/problem?id ...

随机推荐

  1. 2016年11月ACM/ICPC亚洲区北京赛赛后总结

    2016年11月12到11月13为期两天的比赛,这是我们这个对第一次去打亚洲区域赛,经过这次比赛,我认识到了自己与别人的差距,也许我们与别人的起点不同,但这不是理由. 这次的比赛12号的热身赛两点开始 ...

  2. item44:将与参数无关的代码抽离template

    编写non-template代码中,重复十分明显:可以很直观的看到代码的重复,然后将它们写成一个新的class或者函数,然后供调用. 编写template代码中,重复是隐晦的:只存在一份templat ...

  3. C++与Lua交互(一)

    引言 之前做手游项目时,客户端用lua做脚本,基本所有游戏逻辑都用它完成,玩起来有点不爽,感觉"太重"了.而我又比较偏服务端这边(仅有C++),所以热情不高.最近,加入了一个端游项 ...

  4. GetStartupInfo 反调试

    在使用 CreateProcess 创建进程时,需要传递 STARTUPINFO 的结构的指针,而常常我们并不会一个一个设置其结构的值,连把其他不用的值清0都会忽略,而 ollydbg 也这样做了,我 ...

  5. NDK中, 如何提高脚本式语言的可读性

    原文来自安卓教程网android.662p.com,转载时请注明文章的来源:http://android.662p.com/thread-5245-1-1.html [概述]     NDK开发中, ...

  6. 按照自己的理解实现比特交换协议(alternating-bit protocol)

    一开始的思路是想写两个程序的,发送端和接收端.但是后来想了下,因为是模拟的,所以不用这么麻烦,直接自己定制场景(比如说丢包阿,包出错阿,超时之类的). 基本上是根据上图所写的,一个函数发包,一个函数接 ...

  7. c# 两个数组比较,将重复部分去掉,返回不重复部分

    List<string> Ashuzu = new List<string>(); Ashuzu.Add("); Ashuzu.Add("); List&l ...

  8. node.js:怎样同时执行多条SQLs,且只有一个回调

    本文主要介绍开源node.js库mysql-queries,其可以同时执行多条SQLs,且只有一个回调.同时抛砖引玉,与大家交流node.js开发经验. node.js很大的特点就是事件驱动.非阻塞和 ...

  9. 一款js点击显示和隐藏的例子(pc,移动端通用)

    html部分: <div id="box"> <div id="box_title">标题</div> <div id ...

  10. ACE_linux:Reactor与Proactor两种模式的区别

    一.概念: Reactor与Proactor两种模式的区别.这里我们只关注read操作,因为write操作也是差不多的.下面是Reactor的做法: 某个事件处理器宣称它对某个socket上的读事件很 ...