#include <bits/stdc++.h>
using namespace std;
// Function to calculate the Euclidean distance from a point (x, 0) on the highway to a BTS at (xi, yi)
long double distance(long double x, long double xi, long double yi) {
return sqrt((x - xi) * (x - xi) + yi * yi);
}
// Function to find the nearest BTS to a point (x, 0) on the highway
long double nearestDistance(long double x, const vector<pair<long long int, long long int>>& stations) {
// Use binary search to find the nearest BTS efficiently
auto it = lower_bound(stations.begin(), stations.end(), make_pair((long long int)x, LLONG_MIN));
long double minDist = 1e18;
// Check the BTS at or after x
if (it != stations.end()) {
minDist = min(minDist, distance(x, it->first, it->second));
}
// Check the BTS before x
if (it != stations.begin()) {
--it;
minDist = min(minDist, distance(x, it->first, it->second));
}
return minDist;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long int N, L;
cin >> N >> L;
vector<pair<long long int, long long int>> stations(N);
for (long long int i = 0; i < N; ++i) {
cin >> stations[i].first >> stations[i].second;
}
// Binary search to find the point x[q] that maximizes the distance to the nearest BTS
long double left = 0.0, right = L;
long double maxDist = 0.0;
// Perform binary search until the search space is small enough
while (right - left > 1e-9) {
long double mid = (left + right) / 2.0;
// Find the nearest distance at mid and mid + epsilon
long double distMid = nearestDistance(mid, stations);
long double 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... |