hdu3714(三分)

题意:

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

解决:

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

 

 1 #include <bits/stdc++.h>
 2 
 3 const int MAXN = 1e4+10;
 4 double eps = 1e-9;
 5 
 6 int n;
 7 int a[MAXN], b[MAXN], c[MAXN];
 8 
 9 double fun(double x)
10 {
11     double res = a[1] * x*x + b[1]*x + c[1];
12     for (int i = 2; i <= n; ++i) {
13         res = std::max(res, a[i] * x *x + b[i] * x + c[i]);
14     }
15     return res;
16 }
17 
18 int main()
19 {
20     int T;
21     scanf("%d", &T);
22     while (T--) {
23         scanf("%d", &n);
24         for (int i = 1; i <= n; ++i)
25             scanf("%d%d%d", a+i, b+i, c+i);
26         double l = 0, r = 1000;
27         while ( (r - l) > eps) {
28 //            printf("l = %f, r = %f\n", l, r);
29             double ml = l + (r - l) / 3;
30             double mr = r - (r - l) / 3;
31             if (fun(ml) > fun(mr))
32                 l = ml + eps;
33             else
34                 r = mr - eps;
35         }
36         printf("%.4f\n", fun(l));
37     }
38 }

 

posted on 2015-11-03 18:02  TakeoffYoung 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/takeoffyoung/p/4933944.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值