# include<stdio.h>
# include<algorithm>
# include<math.h>
using namespace std;
struct point
{
double left;
double right;
}s[10005];
bool cmp(point x,point y)
{
return x.left<y.left;
}
int main()
{
int N,n;
double w,h;
scanf("%d",&N);
while(N--)
{
int i,flag=0,count=0;
double x,r,l,sum,max;
scanf("%d%lf%lf",&n,&w,&h);
h=h/2;
for(i=0;i<n;i++)
{
scanf("%lf%lf",&x,&r);
l=sqrt(r*r-h*h);
s[i].left=x-l;
s[i].right=x+l;
}
sort(s,s+n,cmp); //左端点由小到大排序
sum=0;
while(sum<w)
{
max=0;
for(i=0;i<n;i++) //找出能覆盖区间的最大右端点
{
if(s[i].left<=sum)
{
if(s[i].right-sum>max)
{
max=s[i].right-sum;
}
}
}
if(max==0)
{
flag=1;
break;
}
else
{
sum=sum+max;
count++;
}
}
if(flag==1)
printf("0\n");
else
printf("%d\n",count);
}
return 0;
}
贪心之区间覆盖
最新推荐文章于 2021-03-19 21:54:55 发布