poj 1328 Radar Installation
#include <iostream>
#include <math.h>
#include<algorithm>
using namespace std;
struct seg
{
double left;double right;
bool operator<(const seg& a)const
{
return left<a.left;
}
}range[1001];
int main()
{
int n,d,i,t=1;double x,y;bool tag;
while(cin>>n>>d)
{
if(n==0&&d==0)break;
tag=0;
for(i=0;i<n;i++)
{
cin>>x>>y;
if(y>d)
tag=1;
if(!tag) //对于某点(x,y)在x轴上(left,right)的范围内都可以覆盖该点
range[i].left=x-sqrt(d*d-y*y),range[i].right=x+sqrt(d*d-y*y);
}
if(tag==1)
cout<<"Case "<<t++<<": -1\n";
else
{
sort(range,range+n); //按左端点从小到大排序
int count=1;double r=range[0].right;
for(i=1;i<n;i++) //只有以下两种情况需要需要处理:
{
if(range[i].left>r)
{
count++;
r=range[i].right;
}
else if(range[i].right<r)
r=range[i].right;
}
cout<<"Case "<<t++<<": "<<count<<"\n";
}
}
return 0;
}