#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e6 + 5;
const double eps = 1e-8;
struct node {
double pos;
int w;
}a[N];
bool cmp(node x, node y) {
return x.pos < y.pos;
}
signed main() {
int n, ts = 0; cin >> n;
for (int i = 1; i <= n; i++) {
int x; cin >> x;
for (int j = 1; j <= x + 1; j++) {
double l = x * 1.0 / j, r = (x + 1) * 1.0 / j;
a[++ts] = {l, 1}, a[++ts] = {r, -1};//
}
}
sort(a + 1, a + 1 + ts, cmp);
int now = 0; double ans = 0;
for (int i = 1; i <= ts; i++) {
if (a[i].w == -1 && now >= n) ans = a[i].pos;
now += a[i].w;
}
printf("%.8lf", ans);
return 0;
}
这份代码 subtask 0 错了,其中 a[++ts] = {l, 1}, a[++ts] = {r, -1}; 应该改为 a[++ts] = {l + eps, 1}, a[++ts] = {r, -1};。
但是为什么将循环的 j 的上限改成 x 也能过呢?按理说多循环一个 x+1 影响的是 ≤1 内的与答案无关啊?