Josephina is a clever girl and addicted to machine learning recently. She
Pays much attention to a method called Linear discriminant analysis, which
has many interesting properties.
In order to test the algorithm ' s efficiency, she collects many datasets.
What's more, each data was divided into the parts:training data and test
Data. She gets the parameters of the model on training data and test the
Model on test data. To hers surprise, she finds each dataset ' s test error curve is just a parabolic curve. A parabolic curve corresponds to a quadratic function. In mathematics, a quadratic function is a polynomial function of the form f (x) = ax2 + bx + C. The quadratic would degrade to linear function if a = 0.
It's very easy to calculate the minimal error if there are only one Test error curve. However, there is several datasets, which means Josephina would obtain many parabolic curves. Josephina wants to get the tuned parameters, the best performance on all datasets. So she should take the all error curves into account, i.e., she had to deal with many quadric functions and make a new error D Efinition to represent the total error. Now, she focuses on the following new function ' s minimum which related to multiple quadric functions. The new function F (x) is defined as follows:f (x) = Max (Si (x)), i = 1...N. The domain of x is [0, 1000]. Si (x) is a quadric function. Josephina wonders the minimum of F (x). Unfortunately, it ' s too hard for her and solve this problem. As a super programmer, can you help her?
Input
The input contains multiple test cases. The first line is the number of cases T (T < 100). Each case is begins with a number n (n≤10000). Following n lines, each line contains three integers a (0≤a≤100), B (|b|≤5000), C (|c|≤5000), which mean the Corre Sponding coefficients of a quadratic function.
Output
For each test case, the output of the answer in a line. Round to 4 digits after the decimal point.
Sample Input
212 0 022 0 02-4 2
Sample Output
0.00000.5000
/* Three points for parabolic type, first increase or decrease the first after the increase accuracy problem. */#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const double eps = 1e-15 const int MAX = 1E4 + 10;int A[max], B[max], c[max];int n;double Check (double x) { double max1 = a[1]*x*x + b[1]*x + c[1]; for (int i = 2; I <= n; i++) max1 = max (max1, a[i]*x*x + b[i]*x + c[i]); return max1;} int main () {int t;scanf ("%d", &t), while (t--) { scanf ("%d", &n); for (int i = 1; I <= n; i++) { scanf ("%d%d%d", &a[i], &b[i], &c[i]); } Double L = 0, r = +; while (L + EPS < r) { Double mid = (L + r)/2; Double Midmid = (mid + R)/2; if (check (mid) > Check (midmid)) { L = mid; } else R = midmid; } printf ("%.4f\n", check (R));} return 0;}
hdu3714--three points--error Curves