结构体数组
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<vector>
#include<stack>
using namespace std;
/*
3
8 20 2
5 3
4 1
1 2
7 2
10 2
13 3
16 2
19 4
3 10 1
3 5
9 3
6 1
3 10 1
5 3
1 1
9 1
*/
struct Data
{
double a;
double b;
}sh[99999];
bool cmp(Data d1, Data d2)//比较器
{
return d1.a < d2.a;
}
int main()
{
int i;
int T;
cin >> T;
int n;
double L;
double W;
while (T--)
{
cin >> n >> L >> W;
i = 0;
for (int j = 0; j < n; j++)
{
double x;
double r;
cin >> x >> r;
if (r < W / 2)
continue;
double d = sqrt(r * r - (W / 2) * (W / 2)); //用a保存左端点,用b保存右端点
sh[i].a = x - d;
sh[i].b = x + d;
i++;
}
n = i; //去掉半径小于W/2后的剩余装置
sort(sh, sh + n, cmp); //左端点递增排序
double Long=0;//右端已经喷水的距离
int flag = 1;
i = 0;
int c = 0;
while (i < n)
{
if (sh[i].a > Long) //有部分无法完全覆盖
{
flag = 0;
break;
}
if (Long >= L) //已经完全覆盖,停止计数
{
break;
}
double max = -1;
while (i < n && sh[i].a <= Long) //在左端点不超过当前已覆盖的范围,选取右端点最大的
{
max = max > sh[i].b ? max : sh[i].b;
i++;
}
Long = max;
c++;
}
if (flag == 0 && Long < L)
cout << "-1" << endl;
else
cout << c << endl;
}
return 0;
}