This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define long long long
using namespace std;
const int N = (int) 1E6;
int n, k;
int x[N], y[N];
/*
为什么这么做的对的,考虑排序线段。
我们排序线段的目的就是为了 连的上!
所以如果线段 i 在 j 之后出现
且 l(i) < l(j)
一定有 r(i) > r(j),这就保证了我们不需要使用排序
*/
bool valid(double a) {
double t = 0;
// t 表示已经可以覆盖 [0, t] 了,初始为空区间
// 因为输入的点的坐标是有序的,所以如果当前的 r 只能覆盖线段
// 的中段的话,t 还会保持是 0
for (int i = 0; i < n; i++) {
if (a < y[i]) {
continue;
}
double l = x[i] - sqrt(1.0 * a * a - 1.0 * y[i] * y[i]);
// 直接 y[i] * y[i] 可能会爆
// 同时,由于 r 大于最大的 abs(y[i]),所以不会出现 sqrt 负数的情况
double r = x[i] + sqrt(1.0 * a * a - 1.0 * y[i] * y[i]);
if (l <= t && r >= t) {
t = r;
}
}
return t >= k;
}
void solve() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
double l = 0, r = 2E9;
for (int i = 0; i < 100; i++) {
double m = (l + r) / 2;
if (valid(m)) {
r = m;
} else {
l = m;
}
}
cout << fixed << setprecision(6);
cout << r << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
t = 1;
for (int i = 0; i < t; i++) {
solve();
}
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... |