这道题目让我明白到: 求圆心在x轴上,d为半径作圆覆盖已知点,可以先过已知点圆圆心,以d为半径与x轴交的两点,改区间变为所求圆的圆心范围;
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=1005;
double d;
int n;
struct Point
{
double x,y;
Point() {}
Point(double xx,double yy):x(xx),y(yy) {}
void read()
{
scanf("%lf%lf",&x,&y);
}
}p[maxn];
struct ext
{
double l,r;
bool operator < (const ext& a) const
{
return (l<a.l);
}
}e[maxn];
double dis(double y)
{
return sqrt(d*d-y*y);
}
double sqr(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
int kase=1;
while(1)
{
scanf("%d%lf",&n,&d);
if(n==0 && d==0) break;
bool flg=true;
for(int i=0;i<n;i++)
{
p[i].read();
if(p[i].y>d)
flg=false;
else
{
double x=dis(p[i].y);
e[i].l=p[i].x-x;
e[i].r=p[i].x+x;
}
}
if(!flg)
printf("Case %d: %d\n",kase++,-1);
else
{
int ans=1;
sort(e,e+n);
double R=e[0].r;
int i=1;
while(i<n)
{
if(e[i].l>R)
{
R=e[i].r;
ans++;
}
else if(e[i].r<R)
{
R=e[i].r;
}
i++;
}
printf("Case %d: %d\n",kase++,ans);
}
}
return 0;
}