三分的第一题
F(x)一定是下凸函数,所以可以用三分
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;
#define INF 1e9
#define maxn 10010
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define mset(x) memset(x,0,sizeof(x))
int kase, n;
int a[maxn], b[maxn], c[maxn];
double F(double x){
double ans = -INF;
rep(i,1,n) ans = max( a[i]*x*x+b[i]*x+c[i], ans );
return ans;
}
int main(){
// freopen("a.txt","r",stdin);
// freopen(".out","w",stdout);
cin>>kase;
while(kase--){
cin>>n;
rep(i,1,n) scanf("%d%d%d", &a[i], &b[i], &c[i]);
double L=0.0, R=1000.0;
rep(i,1,100){
double m1 = L+(R-L)/3;
double m2 = R-(R-L)/3;
if(F(m1)<F(m2)) R = m2;
else L = m1;
}
printf("%.4lf\n", F(L));
}
return 0;
}