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. [Tools] 使用work2013发布博客

    参考园子里推荐的方式,觉得使用word发布挺好的,尝试了一下,还不错,记录下来备用   参考连接: http://www.cnblogs.com/liuxianan/archive/2013/04/1 ...

  2. JSON资料汇总

    网络入门学习资料 1.W3School的JSON教程:http://www.w3school.com.cn/json/index.asp 2.Introducing JSON[介绍JSON]:http ...

  3. mac上创建MySQL的基本步骤

    首先得安装环境与MySQL的软件 安装环境的软件在这里我用的是:jdk-8u111-macosx-x64.dmg MySQL:mysql-5.7.16-osx10.11-x86_64.dmg 安装好了 ...

  4. 玲珑杯1007-A 八进制大数加法(实现逻辑陷阱与题目套路)

    题目连接:http://www.ifrog.cc/acm/problem/1056 DESCRIPTION Two octal number integers a, b are given, and ...

  5. phpstudy配置ssl

    https://yunpan.cn/cPEyzVycbkiE3 (提取码:03aa) 1.重写规则:http://www.cnphp.info/htaccess-rewrite.html 2.相关文档 ...

  6. kylin cube测试时,报错:org.apache.hadoop.security.AccessControlException: Permission denied: user=root, access=WRITE, inode="/user":hdfs:supergroup:drwxr-xr-x

    异常: org.apache.hadoop.security.AccessControlException: Permission denied: user=root, access=WRITE, i ...

  7. AndroidTips:selector的disable状态为什么无效?

    正确的姿势: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android=& ...

  8. XSS 跨站脚本攻击之构造剖析(一)

    1.XSS-Filter:跨站脚本过滤器,用于分析用户提交的输入,并消除潜在的跨站脚本攻击 (1)XSS Filter实际上是一段精心编写的过滤函数作用是过滤XSS跨站脚本代码: (2)绕过XSS F ...

  9. 《DSP using MATLAB》示例Example5.3

  10. psql-02基本语法

    客户端 数据库: 创建:createdb mydb; 删除: dropdb mydb; 连接: 连接: psql mydb; 断开连接: \q 查看当前版本: select version(); 直接 ...