有个问题
查看原帖
有个问题
731925
happy_zero楼主2024/6/30 22:33
#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};。

但是为什么将循环的 jj 的上限改成 xx 也能过呢?按理说多循环一个 x+1x+1 影响的是 ≤1\le 1 内的与答案无关啊?

2024/6/30 22:33
加载中...