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. Win7系统怎么开启远程桌面?Win7远程桌面怎么用(转)

    远程桌面服务开启之后,可以方便的远程管理服务器或计算机.为生活和工作带来不少便利呢,很多小伙伴还不知道怎么开启win7远程桌面吧(下面咗嚛以内网远程桌面为例)   工具/原料 Win7 Win7远程桌 ...

  2. update comboBox

    /// <summary> /// AutoCompleteComboBox /// </summary> public class AutoCompleteComboBox ...

  3. CF735C 数论\平衡树叶子节点的最大深度\贪心\斐波那契\条件归一化

    http://codeforces.com/problemset/problem/735/C 题意..采用淘汰赛制..只要打输就退出比赛..而且只有两个选手打过的场数 相差不超过1才能比赛..最后问你 ...

  4. sql 数字转人民币大写函数(两种方法)

    ,)) returns @rmb table( 亿 ) ,仟万 ) ,佰万 ) ,拾万 ) ,万 ) ,仟 ) ,佰 ) ,拾 ) ,元 ) ,角 ) ,分 )) as begin insert in ...

  5. WPD:Page Download Time Breakdown选项详解

    WPD:Page Download Time Breakdown选项详解 “页面下载时间细分”图显示每个页面组件下载时间的细分,可以根据它确定在网页下载期间事务响应时间缓慢是由网络错误引起还是由服务器 ...

  6. PS切图的几种方式

    方法一 点击图层右键-->导出为 导出需要的格式与大小 方法二 选择多个图层右键--->快速导出为PNG(导出的名字就是图层名字) 方法三

  7. FileSeek文件内容搜索工具下载

    Windows 内建的搜索功能十分简单,往往不能满足用户的需要.很多的第三方搜索工具因此诞生,比如 Everything,Locate32等. 而FileSeek也是一款不错的搜索工具,其不同于其他搜 ...

  8. @import与link

    本质上,这两种方式都是为了加载CSS文件,但还是存在着细微的差别. 1. 老祖宗的差别.link属于XHTML标签,而@import完全是CSS提供的一种方式. link标签除了可以加载CSS外,还可 ...

  9. cf429B dp递推

    Description Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to loo ...

  10. 线段树(多维+双成段更新) UVA 11992 Fast Matrix Operations

    题目传送门 题意:训练指南P207 分析:因为矩阵不超过20行,所以可以建20条线段的线段树,支持两个区间更新以及区间查询. #include <bits/stdc++.h> using ...