modified: 28.cpp

This commit is contained in:
hanyixuanten
2026-08-16 19:56:53 +08:00
parent 22d22c7eb9
commit d59f535602
+13 -27
View File
@@ -5,44 +5,30 @@ int n, d;
struct node struct node
{ {
int x, y; int x, y;
int xl, xr; double xl, xr;
const bool operator<(node b) const
{
return xr > b.xr;
}
} is[1005]; } is[1005];
int main() int main()
{ {
scanf("%d%d", &n, &d); scanf("%d%d", &n, &d);
int minl = INT_MAX, maxl = INT_MIN;
for (int i = 1; i <= n; ++i) for (int i = 1; i <= n; ++i)
{ {
scanf("%d%d", &is[i].x, &is[i].y); scanf("%d%d", &is[i].x, &is[i].y);
if (is[i].y > d) if (abs(is[i].y) > d)
{ {
puts("-1"); puts("-1");
return 0; return 0;
} }
is[i].xl = is[i].x - sqrt(d * d - is[i].y * is[i].y); double len = sqrt(1.0 * d * d - 1.0 * is[i].y * is[i].y);
is[i].xr = is[i].x + sqrt(d * d - is[i].y * is[i].y); is[i].xl = is[i].x - len, is[i].xr = is[i].x + len;
minl = min(minl, is[i].xl);
maxl = max(maxl, is[i].xr);
} }
sort(is + 1, is + n + 1, [](node x, node y) sort(is + 1, is + n + 1, [](const node &x, const node &y)
{ return x.xl < y.xl; }); { return x.xr < y.xr; });
int ans = 0, now = 1; int ans = 0;
int maxans = 0; double now = -DBL_MAX;
priority_queue<node> q; const double eps = 1e-10;
for (int t = minl; t <= maxl; ++t) for (int i = 1; i <= n; ++i)
{ if (now + eps < is[i].xl)
while (!q.empty() && q.top().xr < t) now = is[i].xr, ++ans;
q.pop(); printf("%d\n", ans);
while (now <= n && is[now].xl >= t)
{
q.push(is[now++]);
maxans = max(maxans, (int)q.size());
}
}
printf("%d\n", maxans);
return 0; return 0;
} }