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

2 1 2 0 0 2 2 0 0 2 -4 2
0.0000 0.5000
#include <bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000, 102400000")
using namespace std;
const int maxn = 10005;
const int inf = 0x3f3f3f3f;
const double eps = 1e-9;
int a[maxn], b[maxn], c[maxn];
int n;
double func(double x){
double maxnum=-inf, f;
for (int i=0; i<n; ++i){
f = a[i]*x*x+b[i]*x+c[i];
maxnum = max(maxnum, f);
}
return maxnum;
}
int main(){
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int T;
scanf("%d", &T);
while (T--){
scanf("%d", &n);
for (int i=0; i<n; ++i)
scanf("%d%d%d", a+i, b+i, c+i);
double l=0.0, r=1000.0, mid, tri;
while (r-l > eps){
mid = (r+l)/2.0;
tri = (r+mid)/2.0;
if (func(mid) > func(tri))
l = mid;
else
r = tri;
}
double ans = func(l);
printf("%.4f\n", ans);
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/silenceneo/article/details/51369956