贪心
求出每个岛屿被雷达覆盖,雷达位置的最左点和最右点
按左值排序
从左向右依次扫描
把雷达的位置放在最右点,如果某岛屿不在范围,就添加雷达
#include <iostream>
#include <math.h>
using namespace std;
const int MAXN=1001;
int n,d;
int sum;
double lefts[MAXN],rights[MAXN];
void qsort(int l,int r)
{
int ll=l,rr=r;
double mid=lefts[(l+r)/2];
while (ll<=rr)
{
while (lefts[ll]<mid) ll++;
while (lefts[rr]>mid) rr--;
if (ll<=rr)
{
swap(lefts[ll],lefts[rr]);
swap(rights[ll],rights[rr]);
ll++;
rr--;
}
}
if (ll<r) qsort(ll,r);
if (rr>l) qsort(l,rr);
}
void solve()
{
double std;
qsort(1,n);
sum=1;
std=rights[1];
for (int i=2;i<=n;i++)
{
if (lefts[i]>std)
{
std=rights[i];
sum++;
}
else
{
if (rights[i]<std)
{
std=rights[i];
}
}
}
}
int main()
{
int t=1;
while(1)
{
cin>>n>>d;
if (n==0&&d==0) break;
int fail=0;
for (int i=1;i<=n;i++)
{
int x,y;
cin>>x>>y;
if (y>d)
{
fail=1;
}
else
{
double l=sqrt((double)(d*d-y*y));
lefts[i]=x-l;
rights[i]=x+l;
}
}
if (fail)
{
cout<<"Case "<<t++<<": "<<-1<<endl;
}
else
{
solve();
cout<<"Case "<<t++<<": "<<sum<<endl;
}
}
return 0;
}