zoukankan      html  css  js  c++  java
  • 三分 HDOJ 3714 Error Curves

    题目传送门

     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
    ", cal (r));
    44     }
    45 
    46     return 0;
    47 }
    编译人生,运行世界!
  • 相关阅读:
    019-centos的yum用法
    018-DNS解析过程与配置DNS服务
    017-linux正则表达式
    016-sed
    014-配置SSH免密钥登录
    013-安装VNC服务
    012-centos6.5配置静态ip
    010-centos上安装matlab
    mysqlbinlog
    更换mysql数据库的datadir目录
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4676356.html
Copyright © 2011-2022 走看看