就是找至少需要多少个圆可以把所有点覆盖完,圆心坐标必须在x轴上,所以当一个海岛坐标的y值大于d时,可以直接打印-1,这种情况不能覆盖完所有的点;其它情况,就是找出海岛对应的在x轴上的坐标点,然后再进行判断即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
#include<set>
#include<vector>
using namespace std;
const int MAX=1005;
struct ARR
{
double l,r;
}arr[MAX];
int comp(ARR a,ARR b)
{
return a.l==b.l?a.r<b.r:a.l<b.l;
}
int main()
{
int t=1,n,d;
while(scanf("%d%d",&n,&d)&&n)
{
bool flag = true;
for(int i = 0; i < n; i++)
{
int a,b;
scanf("%d%d",&a,&b);
if(b>d)
flag=false;
double temp= sqrt(d * d - b * b);
arr[i].l = a - temp; arr[i].r = a + temp;
}
if(flag==false)
{
cout << "Case " << t++ << ": -1" << endl ;
continue;
}
sort(arr, arr+n,comp);
int ans = 1;
double k= arr[0].r;
for(int i=1;i<n;i++)
{
if(k > arr[i].r)
k = arr[i].r;
else if(k<arr[i].l)
{
ans++;
k=arr[i].r;
}
}
cout << "Case " << t++ << ": " << ans << endl;
}
return 0;
}