#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ld dist(ld x, ll xi, ll yi) {
return sqrt((x - xi)*(x - xi) + (ld)(yi*yi));
}
// Function to find the nearest BTS to a point x on the highway
ld nearestDistance(ld x, const vector<pair<ll, ll>>& stations) {
auto it = lower_bound(stations.begin(), stations.end(), make_pair((ll)x, LLONG_MIN));
ld minDist = 1e18;
// Check the BTS at or after x
if (it != stations.end()) {
minDist = min(minDist, dist(x, it->first, it->second));
}
// Check the BTS before x
if (it != stations.begin()) {
--it;
minDist = min(minDist, dist(x, it->first, it->second));
}
return minDist;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll N, L;
cin >> N >> L;
vector<pair<ll, ll>> stations(N);
for (auto& s : stations) cin >> s.first >> s.second;
// Binary search to find the point x[q] that maximizes the distance to the nearest BTS
ld left = 0.0, right = L;
ld maxDist = 0.0;
// Perform binary search until the search space is small enough
for (int iter = 0; iter < 100; ++iter) {
ld mid = (left + right) / 2.0;
// Find the nearest distance at mid and mid + epsilon
ld distMid = nearestDistance(mid, stations);
ld distMidEpsilon = nearestDistance(mid + 1e-9, stations);
// Update the maximum distance found so far
maxDist = max(maxDist, distMid);
// Adjust the search boundaries based on whether we are on the increasing or decreasing part
if (distMid < distMidEpsilon) {
left = mid;
} else {
right = mid;
}
}
// Output the result with the required precision
cout << fixed << setprecision(6) << maxDist << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |