点击打开链接
///根据坐标和半径 得到每个喷水设置能够覆盖的左右坐标
///然后按左坐标从小到大排序
///筛选时候如果喷水设置的左坐标小于等于起始点star用while循环寻找能够覆盖最大的右坐标
///然后更新起始点star为寻找到的最大右坐标
///区间覆盖
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct node
{
double left,right;
}c[10005];
bool cmp(node x,node y)///左坐标排序
{
return x.left<y.left;
}
int main()
{
int N,n;
double w,h,x,r,temp,star,p;
scanf("%d",&N);
while(N--){
scanf("%d %lf %lf",&n,&w,&h);
for(int i=0;i<n;i++){
scanf("%lf %lf",&x,&r);
if(r<=h/2)///如果半径小于高的一半 不能覆盖,temp=0;
temp=0;
else
temp=sqrt(pow(r,2)-pow(h/2,2));
c[i].left=x-temp,c[i].right=x+temp;
}
sort(c,c+n,cmp);
int sum=0;
star=0;
for(int i=0;i<n;i++){
if(c[i].left<=star){///找到第一个左坐标小于等于star的.确保左边能够覆盖否则无解
p=c[i].right;
while(c[i].left<=star){///寻找最大的右坐标
p=max(p,c[i].right);///合理的右边最大,满足情况下的最长的区间
if(i==n) break;
i++;
}
star=p;///更新右坐标,新的起点
i--,sum++;///在刚刚的while循环i++了
}
if(star>=w)///提前结束循环
break;
}
if(star>=w)
printf("%d\n",sum);
else
printf("0\n");
}
return 0;
}