LA 5009 三分

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 10000 + 10;
int n, a[maxn], b[maxn], c[maxn];
double F(double x)
{
	double ans = a[0] * x * x + b[0] * x + c[0];
	for (int i = 1; i < n; i++)
		ans = max(ans, a[i] * x * x + b[i] * x + c[i]);
	return ans;
}
int main(int argc, char const *argv[])
{
	int T;
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &n);
		for (int i = 0; i < n; i++)
			scanf("%d%d%d", a + i, b + i, c + i);
		double L = 0.0, R = 1000.0;
		for (int i = 0; i < 100; i++)
		{
			double m1 = L + (R - L) / 3;
			double m2 = R - (R - L) / 3;
			if (F(m1) < F(m2)) R = m2;
			else L = m1;
		}
		printf("%.4lf\n", F(L));
	}
	return 0;
}



单峰函数使用三分来求值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值