三分求调,样例过了
  • 板块P1883 函数
  • 楼主duanzx
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/10/28 15:07
  • 上次更新2023/10/28 16:16:17
查看原帖
三分求调,样例过了
1008172
duanzx楼主2023/10/28 15:07
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e4 + 10;
int a[N];
int b[N];
int c[N];
double y(int n, int x) {
	double k = x / 10000.0;
	double ans = -1e9;
	for (int i = 1; i <= n; i ++) {
		ans = max(ans, a[i] * k * k + b[i] * k + c[i]);
	}
	return ans;
}

void solve() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	int l = 0, r = 1e7;
	while (r - l >= 3) {
		int m1 = l + (r - l) / 3;
		int m2 = r - (r - l) / 3;
		if (y(n, m1) > y(n, m2)) l = m1;
		else r = m2;
	}
//	cout << l << ' ' << r << ' ';
	cout << fixed << setprecision(4) << min(y(n, l) , min(y(n, min(r, l + 1)), y(n, r)));
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while (T --) {
		solve();
		if (T) cout << '\n';
	}
	return 0;
}
2023/10/28 15:07
加载中...