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);
} }
}

最新文章

  1. 深度剖析 | 基于大数据架构的BI应用
  2. RS-232 vs. TTL Serial Communication(转载)
  3. SQL/LINQ/Lamda 写法[转发]
  4. Java基础-重写System.out.println方法
  5. 普通View的measure流程
  6. [Html5]sessionStorage和localStorage的区别
  7. elasticsearch介绍集群,模拟横向扩展节点、节点宕机、改变分片
  8. DIV背景半透明文字不半透明的样式
  9. UVa 11572 Unique snowflakes【滑动窗口】
  10. 关于github在mac 10.10上无法提交代码的解决办法---备用
  11. 有理数类 Java BigInteger实现
  12. Visual Studio2013使用Microsoft Office Document Imaging(MODI)的方法
  13. Objective-C:KVC
  14. Linux进程和线程的比較
  15. Ubuntu Hash Sum mismatch 解决方法
  16. Java IO之File和IO
  17. tomcat启动不了,内存溢出
  18. &#9733;不容错过的PPT教程!
  19. linux使用.net core 创建简单的MVC
  20. 微信开发者工具_小程序js文件后面的M代表什么

热门文章

  1. Oracle异机恢复
  2. #define及其用法
  3. 在IDEA里gradle配置和使用
  4. 进击的Python【第十二章】:mysql介绍与简单操作,sqlachemy介绍与简单应用
  5. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
  6. Oracle查看所有表空间的数据使用情况
  7. .NET框架概述
  8. Web常见几种攻击与预防方式
  9. 移动web开发填坑(一)
  10. JAVA300集笔记