码迷,mamicode.com
首页 > 其他好文 > 详细

三分 HDOJ 3714 Error Curves

时间:2015-07-25 19:51:41      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 1 /*
 2     三分:凹(凸)函数求极值
 3 */
 4 #include <cstdio>
 5 #include <algorithm>
 6 #include <cstring>
 7 #include <cmath>
 8 using namespace std;
 9 
10 const int MAXN = 1e4 + 10;
11 const int INF = 0x3f3f3f3f;
12 const double EPS = 0.0000000001;
13 struct F    {
14     double a, b, c;
15 }f[MAXN];
16 int n;
17 
18 double cal(double x)    {
19     double res = -INF;
20     for (int i=1; i<=n; ++i)    {
21         res = max (res, f[i].a * x * x + f[i].b * x + f[i].c);
22     }
23     return res;
24 }
25 
26 int main(void)  {       //HDOJ 3714 Error Curves
27     //freopen ("HDOJ_3714.in", "r", stdin);
28 
29     int T;  scanf ("%d", &T);
30     while (T--) {
31         scanf ("%d", &n);
32         for (int i=1; i<=n; ++i)    {
33             scanf ("%lf%lf%lf", &f[i].a, &f[i].b, &f[i].c);
34         }
35 
36         double l = 0.0, r = 1000.0;
37         for (int i=1; i<=100; ++i)  {
38             double mid = (l + r) / 2;
39             double rmid = (mid + r) / 2;
40             if (cal (mid) < cal (rmid)) r = rmid;
41             else    l = mid;
42         }
43         printf ("%.4f\n", cal (r));
44     }
45 
46     return 0;
47 }

 

三分 HDOJ 3714 Error Curves

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4676356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!