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 先算出每个岛放探测雷达的x坐标范围,b为雷达探测半径,岛的坐标为(x,y),雷达的坐标范围是(x-sqrt(d*d-y*y),x+sqrt(d*d-y*y)),定义sum=1,i从1开始,每个坐标范围左右边界与上一个坐标范围的右边界比较,具体看代码。
 #include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
struct stu
{
double l,r;
} st[];
bool cmp(stu a,stu b)
{
return a.l<b.l;
}
int main()
{
int a,s,k=,sum,i;
double b,x,y,sky;
while(scanf("%d %lf",&a,&b) &&!(a==&&b==))
{
s=;
k++;
for(i = ; i < a ; i++)
{
scanf("%lf %lf",&x,&y);
if(b < || y > b)
{
s=-;
}
st[i].l=x-sqrt(b*b-y*y);
st[i].r=x+sqrt(b*b-y*y);
}
if(s == -) printf("Case %d: -1\n",k);
else
{
sort(st,st+a,cmp);
sum=;
sky=st[].r;
for(i = ; i < a ; i++)
{
if(st[i].r <= sky)
{
sky=st[i].r;
}
else
{
if(st[i].l > sky)
{
sky=st[i].r;
sum++;
}
}
}
printf("Case %d: %d\n",k,sum);
} }
}

贪心 Radar Installation (求最少探测雷达)的更多相关文章

  1. [ACM_贪心] Radar Installation

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28415#problem/A 题目大意:X轴为海岸线可放雷达监测目标点,告诉n个目标点和雷 ...

  2. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

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

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

  4. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

  5. Radar Installation POJ - 1328(贪心)

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

  6. poj 1328 Radar Installation(贪心+快排)

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

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

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

  8. 【OpenJ_Bailian - 1328】Radar Installation (贪心)

    Radar Installation 原文是English,直接上中文 Descriptions: 假定海岸线是无限长的直线.陆地位于海岸线的一侧,海洋位于另一侧.每个小岛是位于海洋中的一个点.对于任 ...

  9. poj 1328 Radar Installation(nyoj 287 Radar):贪心

    点击打开链接 Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43490   Accep ...

随机推荐

  1. LuoguP1063 能量项链【区间Dp】

    前天测试考了QAQ.这么经典的区间dp不再开一文好像有点可惜. 内容是从模拟赛结题报告中copy来的.QAQ noip能量项链原题. https://www.luogu.org/problemnew/ ...

  2. A - Supercentral Point CodeForces - 165A

    One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of point ...

  3. NOI2018D2T1 屠龙勇士

    安利一下松松松的OJ: 传送门 Description: ​ 有N条巨龙, 对于每个龙含有\(a_i\)的生命, 你有N + M把砍刀, 其中M把是直接给你的, N把是杀死对应的巨龙才能获得的, 每把 ...

  4. hdu 4565 So Easy! (共轭构造+矩阵快速幂)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4565 题目大意: 给出a,b,n,m,求出的值, 解题思路: 因为题目中出现了开根号,和向上取整后求 ...

  5. how-to-fix-fs-re-evaluating-native-module-sources-is-not-supported-graceful

    http://stackoverflow.com/questions/37346512/how-to-fix-fs-re-evaluating-native-module-sources-is-not ...

  6. C#---数据库访问通用类、Access数据库操作类、mysql类 .[转]

    原文链接 //C# 数据库访问通用类 (ADO.NET)using System;using System.Collections.Generic;using System.Text;using Sy ...

  7. 移动端rem单位用法

    1.rem(font size of the root element)是指相对于根元素的字体大小的单位,em(font size of the element)是指相对于父元素的字体大小的单位.它们 ...

  8. AJPFX理解反射及反射的应用

    怎么理解反射,反射的应用        反射就是把Java类中的各种成分映射成相应的Java类.        一般情况下我们要解决某个问题,先找到相关的类,创建该类的对象,然后通过该对象调用对应的方 ...

  9. eclipse debug java 源码

    当我们需要研究java SE的时候,debug 源码是个不错的选择,可以帮助我们清楚了解java 封装jar包的具体实现. 因为oracle 提供的源码jar包为了节省空间,所以没有将调试信息一起打包 ...

  10. iOS Programming Dynamic Type 2

    iOS Programming Dynamic Type  2       You will need to update two parts of this view controller for ...