题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=287
解题思路:首先求出来每个点的临界区域,即这个圆心能够将其覆盖的范围。。。求出了每个点的覆盖区域,那么问题就转化为区间的覆盖问题了。。。在算重叠的部分花了好长的时间而且还没有写好,还是没有把出现的情况讨论清楚。。。
AC:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct node
{
double left,right;
}a[1005];
bool cmp(node a,node b)
{
return a.left < b.left;
}
int main()
{
int n,d,cas = 1;
bool flag;
while(scanf("%d%d",&n,&d)!=EOF && n + d)
{
flag = false;
for(int i = 0; i < n; i++)
{
int x,y;
scanf("%d%d",&x,&y);
double tmp = double(d*d - y*y);
if(tmp >= 0)
{
tmp = sqrt(tmp);
a[i].left = x - tmp;
a[i].right = x + tmp;
}
else flag = true;
}
if(flag)
{
printf("Case %d: -1\n",cas++);
continue;
}
sort(a,a+n,cmp);
int cnt = 1;
double t = a[0].right;
for(int i = 1; i < n; i++)
{
if(a[i].left > t)
{
cnt++;
t = a[i].right;
}
else
{
if(a[i].right < t)
t = a[i].right;
}
}
printf("Case %d: %d\n",cas++,cnt);
}
return 0;
}