标签:
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
struct qj
{
double l, r;
}b[1110];
bool cmp(qj a, qj b)
{
if(a.r == b.r)
return a.l > b.l;
return a.r < b.r;
}
int main()
{
double x, y;
double d,temp;
int i, n, count, num=1;
while(~scanf("%d %lf", &n, &d), n&&d)
{
for(i = 0; i < n; i ++)
{
scanf("%lf %lf", &x, &y);
b[i].l = x - sqrt(d*d - y*y);//可求出卫星在X轴上的区间,根据勾股定理
b[i].r = x + sqrt(d*d - y*y);
}
sort(b, b + n, cmp);
count = 1;//记录卫星总数,现在右区间长度最小的地方安装一个卫星,这样卫星覆盖的范围才最广
temp = b[0].r;
for(i = 1; i < n; i ++)
{
if(b[i].l > temp)//看排名后的左区间是否在上一个卫星覆盖范围之内
{
temp = b[i].r;
count++;
}
}
printf("Case %d: %d\n", num++, count);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/digulove/p/4693238.html