「一本通 1.2 例 3」曲线
三分,主要解决单峰问题(求单峰),不过递增或递减
链接:https://loj.ac/p/10013
画图可以看出F(x)是一个单峰函数,在函数定义域内使用三分法即可。
int a[N], b[N], c[N]; int t, n; inline double cal(double x) { double res = -INF; for (int i = 1; i <= n; i++) { res = max(res, a[i] * x * x + b[i] * x + 1.0 * c[i]); } return res; } int main() { t = read(); while (t--) { n = read(); for (int i = 1; i <= n; i++) { a[i] = read(), b[i] = read(), c[i] = read(); } double l = 0, r = 1000; while (r - l >= eps) { double lmid = l + (r - l) / 3; double rmid = r - (r - l) / 3; if (cal(lmid) < cal(rmid)) r = rmid; else l = lmid; } printf("%.4lf\n", cal(l)); } }