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. 拉姆达表达式 追加 条件判断 Expression<Func<T, bool>>

    public static class PredicateBuilder { /// <summary> /// 机关函数应用True时:单个AND有效,多个AND有效:单个OR无效,多个 ...

  2. layout_weight

    最近写Demo,突然发现了Layout_weight这个属性,发现网上有很多关于这个属性的有意思的讨论,可是找了好多资料都没有找到一个能够说的清楚的,于是自己结合网上资料研究了一下,终于迎刃而解,写出 ...

  3. PowerShell 管道和对象成员

    2.1  管道 在各种现代的shell中,均支持管道的概念. 管道的最大特点就是:  前一个命令的输出作为后一个命令的输入.cmd.bash均支持管道的概念,这里我就不多说了,下面我们说说PS中 管道 ...

  4. 微信授权登陆接入第三方App(步骤总结)Android

    微信授权登陆接入第三方App(步骤总结)Android Android App实现第三方微信登录

  5. 深入浅出CChart 每日一课——第十八课 女神的套娃,玩转对话框

    前面笨笨已经给大家展示了CChart编程的N个例子.这些例子中,我们的CChart图像都是绘制在程序的主窗口中的. 在很多情况下,我们面对的情形不是这样的.这节课笨笨就给大家介绍一下怎样在对话框中用C ...

  6. libeXosip2(1-1) -- How-To initialize libeXosip2.

    How-To initialize libeXosip2. The eXtented eXosip stack Initialize eXosip and prepare transport laye ...

  7. 应用程序打包(ipa)

    如果想让用户可以安装ipa, 必须在打包程序的时候说清楚哪一个应用程序(appid)可以安装到哪一台设备上.(UDID). 原理: 要想打包, 告诉苹果, 哪一台电脑可以进行打包 步骤: 让电脑端具备 ...

  8. <% %> 、 <%= %> 、<%# %> 的区别

    1,<% %>用来绑定后台代码    中间一般放函数或者方法,典型的asp程序写法. 在前台页面可以写后台代码                 相当于开辟了C#空间,可以写C#代码 2,& ...

  9. URLConnection的连接、超时、关闭用法总结

    Java中可以使用HttpURLConnection来请求WEB资源. 1. URL请求的类别 分为二类,GET与POST请求.二者的区别在于:      a:) get请求可以获取静态页面,也可以把 ...

  10. mmc加工配套问题

    题目如下,本题还有其它解.