Radar Installation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 68578   Accepted: 15368

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 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 需要判断d<0,a[i].y>d情况。
首先,按照x坐标排序,对于每个岛屿求出雷达所能放置的区间,然后对这些进行处理,x1,x2;
设当前雷达放置位置为nowx,对于下一个区间,如果写x1>nowx,显然多需要一个雷达,反之如果nowx>x1,nowx=min(nowx,x2);
 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
struct node
{
int x,y;
}a[+];
bool cmp(node q,node p)
{
if(q.x==p.x)
return q.y>=p.y;
return q.x<p.x;
}
int main()
{
int n,d;
int i,j;
int k=;
freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&d))
{
int coun=;
if(n==&&d==)
break;
bool flag=;
for(i=;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
if(a[i].y>d)
flag=;
}
if(flag||d<=)
{
printf("Case %d: -1\n",k++);
continue;
}
sort(a,a+n,cmp);
double nowx=sqrt(double(d*d-a[].y*a[].y))+a[].x;
double x1,x2,temp;
for(i=;i<n;i++)
{
temp=sqrt(double(d*d-a[i].y*a[i].y));
x1=a[i].x-temp;
x2=a[i].x+temp;
if(x1>nowx)
{
nowx=x2;
coun++;
}
else if(nowx>x2)
nowx=x2;
}
printf("Case %d: %d\n",k++,coun);
}
}

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. Radar Installation POJ - 1328

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

  4. Greedy:Radar Installation(POJ 1328)

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

  5. UVALive 2519 Radar Installation 雷达扫描 区间选点问题

    题意:在坐标轴中给出n个岛屿的坐标,以及雷达的扫描距离,要求在y=0线上放尽量少的雷达能够覆盖全部岛屿. 很明显的区间选点问题. 代码: /* * Author: illuz <iilluzen ...

  6. POJ 1328 Radar Installation 【贪心 区间选点】

    解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...

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

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

  8. POJ 1328 Radar Installation(很新颖的贪心,区间贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 106491   Accepted: 2 ...

  9. POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)

    Input The input consists of several test cases. The first line of each case contains two integers n ...

随机推荐

  1. 六度分离--hdu1869

    六度分离 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. jquery-1.10.2 获取checkbox的checked属性总是undefined

    项目中用的jquery-1.10.2 需要检测一个checkbox的选中状态,想当然的用 .attr("checked") ,结果发现,无论是否选中,这个值都是 undefined ...

  3. linux安装xunsearch

    首先要确保ubuntu安装了gcc g++ make sudo apt-get install make gcc g++ 然后安装zlib,用来解压的: apt-get install zlib1g- ...

  4. BZOJ 1264 基因匹配Match(LCS转化LIS)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1264 题意:给出两个数列,每个数列的长度为5n,其中1-n每个数字各出现5次.求两个数列 ...

  5. 【剑指offer】面试题34:丑数

    题目: 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 思路: 第一 ...

  6. [Linux] killall 、kill 、pkill 命令详解

    killall 命令 Linux系统中的killall命令用于杀死指定名字的进程(kill processes by name).我们可以使用kill命令杀死指定进程PID的进程,如果要找到我们需要杀 ...

  7. qt画刷和画笔

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #画刷和画笔:QBrush 定义了 QPainter 的填充模式,具 ...

  8. OpenVPN莫名其妙断线的问题及其解决

    1.问题 不得不说,这是一个OpenVPN的问题,该问题几乎每个使用OpenVPN的人都碰到过,也有很多人在网上发问,然而一直都没有人能给出解决办法,甚至很多帖子上表示因为这个问题而放弃了使用Open ...

  9. C++中,访问字符串的三种方法

    1.用字符数组存放一个字符串 程序1:定义一个字符数组并初始化,然后输出其中的字符串. #include<iostream> using namespace std; int main() ...

  10. SAX解析和生成XML文档

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本人声明.否则将追究法律责任. 作者: 永恒の_☆ 地址: http://blog.csdn.net/chenghui031 ...