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. phpcms_v9 多图字段 内容页,首页,分页自定义字段调用

    phpcms_v9 多图字段 内容页,首页,分页自定义字段调用 说明:自定义多图字段名 shigongtu 1 内容页调用 {loop $shigongtu $r}      <img src= ...

  2. 静态内容生成器——Wyam

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:今天继续静态网站的话题,介绍我选用的一个使用.NET开发的静态内容生成器--Wyam. ...

  3. 封装用className选元素

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. nginx、php-fpm、mysql用户权限解析

    nginx本身不能处理PHP,它只是个web服务器.当接收到客户端请求后,如果是php请求,则转发给php解释器处理,并把结果返回给客户端.如果是静态页面的话,nginx自身处理,然后把结果返回给客户 ...

  5. hdu2476 String painter(区间dp)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2476 Problem Description There are two strings ...

  6. poj1061 Exgcd

    #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> usin ...

  7. 《DSP using MATLAB》示例Example5.2

    代码: L = 5; N = 20; k = [-N/2:N/2]; % square wave parameters xn = [ones(1,L), zeros(1,N-L)]; % Sq wav ...

  8. POJ1637 Sightseeing tour(判定混合图欧拉回路)

    有向连通图存在欧拉回路的充要条件是所有点入度=出度. 首先随便给定所有无向边一个方向(不妨直接是u->v方向),记录所有点的度(记:度=入度-出度). 这时如果有点的度不等于0,那么就不存在欧拉 ...

  9. 每天一个linux命令--awk

    统计计算日志 pmail@app2linux04 performance]$ grep 'user:logBehaviorAction' performance.log|awk -F '|' '{pr ...

  10. ural 1146. Maximum Sum

    1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...