首页 > 代码库 > [HDOJ3714]Error Curves(三分)

[HDOJ3714]Error Curves(三分)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3714

题意:求n个二次函数在[0,1000]的最小值。

三分枚举。

 1 #include <bits/stdc++.h> 2 using namespace std; 3  4 const int maxn = 10100; 5 const double eps = 1e-9; 6 double a[maxn], b[maxn], c[maxn]; 7 int n; 8  9 double f(double x) {10   double ret = -1000000000;11   for(int i = 1; i <= n; i++) {12     double y = a[i]*x*x+b[i]*x+c[i];13     ret = max(ret, y);14   }15   return ret;16 }17 18 double ts() {19   double lo = 0, hi = 1000.0;20   double ret1, ret2;21   while(hi - lo >= eps) {22     double mid = (lo + hi) / 2.0;23     double mimid = (mid + hi) / 2.0;24     ret1 = f(mid);25     ret2 = f(mimid);26     if(ret1 > ret2) lo = mid;27     else hi = mimid;28   }29   return ret1;30 }31 32 int main() {33   //freopen("in", "r", stdin);34   int T;35   scanf("%d", &T);36   while(T--) {37     scanf("%d", &n);38     for(int i = 1; i <= n; i++) {39       scanf("%lf %lf %lf", &a[i], &b[i], &c[i]);40     }41     printf("%.4lf\n", ts());42   }43   return 0;44 }

 

[HDOJ3714]Error Curves(三分)