思路
代码
#include <cstdio>
#include <cmath>
int n, L, W, t, att, ans;
double w;
struct Node {
double a, b;
} arr[15006], tmp;
inline void read(int &x) {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
x = s * f;
}
inline void write(int x) {
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
void qsort(int L, int R) {
int l = L, r = R;
double mid = arr[l + r >> 1].a;
while (l < r) {
while (arr[l].a < mid) l++;
while (arr[r].a > mid) r--;
if (l <= r) {
tmp = arr[l];
arr[l] = arr[r];
arr[r] = tmp;
l++, r--;
}
}
if (l < R) qsort(l, R);
if (L < r) qsort(L, r);
}
int main() {
read(t);
while (t--) {
ans = 0, att = 0;
read(n), read(L), read(W);
double w = W / 2.0, ww = w * w, wx;
for (int i = 1, a, b; i <= n; ++i) {
read(a), read(b);
if (b <= w) continue;
wx = sqrt(b * b - ww);
arr[++att].a = a - wx;
arr[att].b = a + wx;
}
qsort(1, att);
double ta = 0.0, tb = 0.0, prea = 0, preb;
while (ta < L) {
tb = ta;
for (int i = prea + 1; i <= att; ++i) {
if (arr[i].a <= ta && arr[i].b > tb) {
tb = arr[i].b;
preb = i;
}
}
ans++;
if (prea == preb) break;
ta = tb, prea = preb;
}
if (ta >= L) write(ans), puts("");
else puts("-1");
}
return 0;
}