Radar Installation

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/C

题目:

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<tex2html_verbatim_mark> distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d<tex2html_verbatim_mark> .

We use Cartesian coordinate system, defining the coasting is the x<tex2html_verbatim_mark> -axis. The sea side is above x<tex2html_verbatim_mark> -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<tex2html_verbatim_mark> - y<tex2html_verbatim_mark>coordinates.

<tex2html_verbatim_mark>

Input

The input consists of several test cases. The first line of each case contains two integers n<tex2html_verbatim_mark>(1n1000)<tex2html_verbatim_mark> and d<tex2html_verbatim_mark> , where n<tex2html_verbatim_mark> is the number of islands in the sea and d<tex2html_verbatim_mark> is the distance of coverage of the radar installation. This is followed by n<tex2html_verbatim_mark> 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个岛屿的坐标,和雷达可以探测的半径。要求用最少的雷达把所有岛屿都探测到(雷达必须放在x轴上),
输出所用雷达的个数。
分析:
将能探测到岛屿的雷达位置区间求出来,这样就将问题转化为了区间覆盖问题。

按照右交点排序,如果i点的左交点在当前雷达右交点的右边 则需安装一个新雷达,更新雷达。

如果不能覆盖记得输出‘-1’。

注意:  如果是按左交点排序,方法相同不过要考虑雷达的左右交点都在当前雷达右交点左边的情况。

 #include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
struct node
{
double l;
double r;
}a[maxn];
double cmp(node a,node b) //进行右交点排序
{
if(a.r==b.r) a.l>b.l;
return a.r<b.r;
}
int main()
{
int n,d,i,j;
double x,y;
int c=,cnt=;
while(cin>>n>>d&&(n||d))
{
c++;
cnt=;
for( i=;i<n;i++)
{
cin>>x>>y;
if(y>d||d<)
{
cnt=-;
continue;}
a[i].l=x-sqrt(d*d-y*y); //求出能探测岛屿最左边雷达的坐标
a[i].r=x+sqrt(d*d-y*y); //最右边的坐标
}
sort(a,a+n,cmp);
for(i=,j=;i<n;i++)
{
if(cnt==-) break;
if(a[j].r<a[i].l)
{
cnt++;
j=i;
}
}
cout<<"Case "<<c<<":"<<' '<<cnt<<endl; }
return ;
}

Radar Installation的更多相关文章

  1. [POJ1328]Radar Installation

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

  2. Radar Installation(贪心)

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

  3. 贪心 POJ 1328 Radar Installation

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

  4. Radar Installation 分类: POJ 2015-06-15 19:54 8人阅读 评论(0) 收藏

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 60120   Accepted: 13 ...

  5. poj 1328 Radar Installation(nyoj 287 Radar):贪心

    点击打开链接 Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43490   Accep ...

  6. Poj 1328 / OpenJudge 1328 Radar Installation

    1.Link: http://poj.org/problem?id=1328 http://bailian.openjudge.cn/practice/1328/ 2.Content: Radar I ...

  7. POJ1328——Radar Installation

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

  8. poj 1328 Radar Installation【贪心区间选点】

    Radar Installation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  9. Radar Installation 贪心

    Language: Default Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42 ...

随机推荐

  1. android studio常见错误

    1.Failed to import new Gradle project: Could not install Gradle distribution from'http://services.gr ...

  2. 在ASP.NET 5项目中使用和调试外部源代码包

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:由于在ASP.NET 5中,项目依赖都是通过"包"来引用,所以使用 ...

  3. VMWARE虚拟机CentOS6.4系统使用主机无线网卡上网的三种方法介绍

    转自:http://www.jb51.net/network/98820.html 如何真正的实现VMWARE虚拟机CentOS6.4系统使用主机无线网卡上网   环境:WIN7旗舰版,台式机,U盘无 ...

  4. ZLL主机接口的信息处理流程

    主机接口的信息处理流程 在我们翻译的文档中是用电脑端来模拟主机的,电脑代替网关发送主机接口命令的环节是在zll_controller.c中实现的,(在下载的文件中已经提供了其对应的可执行文件zllCm ...

  5. JQuery Event属性说明

    JQuery事件中的Event属性是经常性的被忽略的.大多数时间你的确不怎么用它,但有些时候它还是有作用的. 如获知触发时用户的环境(是否按了shift etc).每个浏览器对event都有不同的地方 ...

  6. linux下vim配置以及一些常用的快捷键

    一些常用的vim编辑器快捷键: h」.「j」.「k」.「l」,分别控制光标左.下.上.右移一格. 按「ctrl」+「b」:屏幕往“后”移动一页. 按「ctrl」+「f」:屏幕往“前”移动一页. 按「c ...

  7. MySQL数据库在WINDOWS系统CMD下的编码问题

    MySQL数据库在WINDOWS系统CMD下的编码问题 1. 查看MySQL数据库编码 * SHOW VARIABLES LIKE 'char%'; 2. 编码解释 * character_set_c ...

  8. MySQL的多表查询(笛卡尔积原理)

    先确定数据要用到哪些表. 将多个表先通过笛卡尔积变成一个表. 然后去除不符合逻辑的数据(根据两个表的关系去掉). 最后当做是一个虚拟表一样来加上条件即可. 注意:列名最好使用表别名来区别. 笛卡尔积 ...

  9. express-7 请求和响应对象(2)

    获取更多信息 如果正在寻找某些功能,首先要查看Express的API文档 如果需要的信息没在文档中,有时就不得不深入研究Express源码; 下面是Express源码的路径说明 lib/applica ...

  10. Spring -配置集合属性

    1 可使用<list> <map> <set>等来配置集合属性2 List <!-- 配置List属性 --> <bean id="pe ...