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

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

Sample Output

Case 1: 2
Case 2: 1 题意:N座岛屿,坐标用xi,yi表示,岛屿都位于x轴上。在x轴上建造雷达,每个雷达的的探测范围是以【x,0】为圆心,半径为R的圆(下半圆一看就没用),问最少几个雷达可以探测全部岛屿? 思路:我们把每个岛屿为圆心,做出x轴上雷达的可行建造区域,那么问题就变成用最小的雷达覆盖最多的区域(每个区域一个雷达)。
我们先将区域按左边界递增排序,每取到一个区间,就记录在这个区间右边界pos,如果下个区间的左边界>pos,说明这个雷达无法探测,需要新建雷达,
否则就pos = min(pos,r),就是让原有的雷达去探测它,但是雷达需要移至两个区间的最小右边界处(交集嘛)。 ①因为要用比较左边界和上一次区间的右边界,所以一定是按照左边界排序的。(这样处理后面的区域和之前区域没啥关系,只和pos有关)
置于为什么pos取右边界,因为右边界代表了雷达最远可放置位置(极值),其包含了区间内可行取值了。(决策包容性?) ②当然如果你反过来,右边界排序,你就需要比较右边界和上一次的左边界也行。
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std; int n,r;
struct Node
{
double l,r;
} L[]; double calc(int y,int r)
{
return sqrt(r*r-y*y);
} int dcmp(double a,double b)
{
if(fabs(a-b) < 1e-)
return ;
else
return a-b > ?:-;
}
bool cmp(Node a,Node b)
{
return dcmp(a.l,b.l)<;
}
int main()
{
int cas = ;
while(~scanf("%d%d",&n,&r) && (n || r))
{
int ans=;
for(int i=; i<=n; i++)
{
double x,y;
scanf("%lf%lf",&x,&y);
if(dcmp(y,r) > )
{
ans = -;
continue;
}
double add = calc(y,r);
L[i].l = x-add;
L[i].r = x+add;
}
if(ans == -){printf("Case %d: -1\n",++cas);continue;}
sort(L+,L++n,cmp);
double pos = -0x3f3f3f3f3f3f3f;
for(int i=; i<=n; i++)
{
if(dcmp(L[i].l,pos)>)
{
ans++;
pos = L[i].r;
}
else
{
pos = min(L[i].r,pos);
}
}
printf("Case %d: %d\n",++cas,ans);
}
}
												

Radar Installation POJ - 1328(贪心)的更多相关文章

  1. Radar Installation POJ - 1328

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

  2. Radar Installation POJ - 1328 (贪心)

    题目大意(vj上的翻译版本) 假定海岸线是无限长的直线.陆地位于海岸线的一侧,海洋位于另一侧.每个小岛是位于海洋中的一个点.对于任何一个雷达的安装 (均位于海岸线上),只能覆盖 d 距离,因此海洋中的 ...

  3. Greedy:Radar Installation(POJ 1328)

    装雷达 题目大意,就是令在海岸线的(直线)一边是海(y>0),另一边是陆地(y<=0),在海岸线上装雷达,雷达可以覆盖的范围为d,海上有岛,(x,y),问你应该怎么装雷达,才能做到技能雷达 ...

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

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

  5. poj 1328贪心

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

  6. poj 1328 贪心

    /* 贪心.... 处理处每个点按照最大距离在x轴上的映射 然后我们就有了一些线段 目的是选取尽量少的点 使得每个线段内都有点出现 我们按照左端点排序 然后逐一处理 假设第一个雷达安在第一个线段的右端 ...

  7. poj1328 Radar Installation —— 贪心

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

  8. 贪心 POJ 1328 Radar Installation

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

  9. POJ 1328 Radar Installation 贪心 A

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

随机推荐

  1. PID控制器开发笔记之一:PID算法原理及基本实现

    在自动控制中,PID及其衍生出来的算法是应用最广的算法之一.各个做自动控制的厂家基本都有会实现这一经典算法.我们在做项目的过程中,也时常会遇到类似的需求,所以就想实现这一算法以适用于更多的应用场景. ...

  2. Linux永久修改IP地址

    通常我们为了快速修改IP地址,会这么做 ifconfig eth0 192.168.0.2 netmask 255.255.255.0 这样修改IP地址后,你再运行ifconfig命令后,的确IP地址 ...

  3. Confluence 6 Cron 表达式

    一个 cron 表达式是以 6-7 时间字段来定义一个计划任务是如何按照时间被执行的.每一个字段中的数据库而已为数字或者是一些特定的字符串来进行表达.每一个字段是使用空格或者 tab 进行分隔的. 下 ...

  4. Confluence 6 从其他备份中恢复数据

    一般来说,Confluence 数据库可以从 Administration Console 或者 Confluence Setup Wizard 中进行恢复. 如果你在恢复压缩的 XML 备份的时候遇 ...

  5. 【数据库】MySQL的左连接、右连接和全连接的实现

    表student:+----+-----------+------+| id | name | age |+----+-----------+------+| 1 | Jim | 18 || 2 | ...

  6. mac 端口占用问题

    查看端口号 终端输入:sudo lsof -i tcp:port 将port换成被占用的端口(如:8086.9998) 将会出现占用端口的进程信息. 杀死占用端口的PID进程 找到进程的PID,使用k ...

  7. 【gearman】gearmand -d 无反应解决

    背景:安装了gearman后,用指令gearmand -d启动后.输入ps -ef|grep gearmand 查找不到.说明服务并没有启动. 查看报错: gearmand -d -l gear.lo ...

  8. Data Preprocess

    本文试图解决一个问题,即我们自定义的数据如何训练模型?初识深度学习,我们接触手写数字识别模型,但是批次数据是mnist已经定义好的,我们现在有自己的图片如何做成批次进行训练模型. 现在我们将准备好的原 ...

  9. ubuntu 调整分辨率

    修改 /etc/X11/xorg.conf配置文件即可

  10. ReactNative——页面跳转

    效果图: 进入工作目录,运行 react-native init NavigatorProject 创建项目NavigatorProject import React, { Component } f ...