您的位置:首页 > 其它

hdu3714(三分)

2015-11-03 18:02 253 查看
题意:

  n个二次函数,求定义域[0, 1000]时候每个函数的最小值当中的最大值。精确到1e-4

解决:

  三分,eps = 1e-9能过,因为二次函数的函数值精确到1e-4所以自变量x精确度必须高于1e-8

#include <bits/stdc++.h>

const int MAXN = 1e4+10;
double eps = 1e-9;

int n;
int a[MAXN], b[MAXN], c[MAXN];

double fun(double x)
{
double res = a[1] * x*x + b[1]*x + c[1];
for (int i = 2; i <= n; ++i) {
res = std::max(res, a[i] * x *x + b[i] * x + c[i]);
}
return res;
}

int main()
{
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d%d%d", a+i, b+i, c+i);
double l = 0, r = 1000;
while ( (r - l) > eps) {
//            printf("l = %f, r = %f\n", l, r);
double ml = l + (r - l) / 3;
double mr = r - (r - l) / 3;
if (fun(ml) > fun(mr))
l = ml + eps;
else
r = mr - eps;
}
printf("%.4f\n", fun(l));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: