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. JS window对象的top、parent、opener含义

    .top 该变更永远指分割窗口最高层次的浏览器窗口.如果计划从分割窗口的最高层次开始执行命令,就可以用top变量. .opener opener用于在window.open的页面引用执行该window ...

  2. 排队论的C实现

    大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang 以下鄙人实现了排队论思想,语言是C语言   #include<stdio.h> #in ...

  3. [Codeforces Round #237 (Div. 2)] A. Valera and X

    A. Valera and X time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. 在win7与XP系统下 C#缺省路径不同

    当我们加载文件时,若只输入文件名,在WIN7下默认是主程序所在文件夹路径 在XP下是上次本程序游览的有效路径 所以以后程序中尽量避免只传文件名

  5. Silverlight信息加密 - 通过Rfc2898DeriveBytes类使用基于HMACSHA1的伪随机数生成器实现PBKDF2

    原文: http://blog.csdn.net/xuyue1987/article/details/6706600 在上一篇文章当中,介绍到了通过Silverlight获取web.config中的值 ...

  6. Merge Sorted Array 解答

    Question Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array ...

  7. IT技术如何转向销售创业

    广州 IT 网友  14:14:10 本人本科软件工程毕业,现在在一家公司做开发(不是很技术的那种),工作接近两年感觉自 己不适合这个行业,想换销售行业,不愿意在做技术.打算从事本行业的销售,老师给点 ...

  8. zedboard--Opencv移植和zedboard测试(十一)

    继上次生成了ARM架构的链接库之后,我们要把他们拷贝到装载有文件系统的SD卡中即可,在拷贝时,最好是/usr/lib下 实践一:将那些lib拷贝到U盘里面,因为之前跑过demo,里面就是一个简易的li ...

  9. IO之内核buffer----"buffer cache"

    举例 一般情况下,Read,write系统调用并不直接访问磁盘.这两个系统调用仅仅是在用户空间和内核空间的buffer之间传递目标数据. 举个例子,下面的write系统调用仅仅是把3个字节从用户空间拷 ...

  10. mysql 编码设置

    (windows下) 打开C:\Program Files\MySQL\MySQL Server 5.0\my.ini (ubuntu下) 打开 /etc/mysql/my.cnf 在[client] ...