Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 1832 | Accepted: 737 |
Description
Input
Output
Sample Input
25 30 3121 -1
Sample Output
25 coconuts, 3 people and 1 monkey 30 coconuts, no solution 3121 coconuts, 5 people and 1 monkey
Source
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 is divided into two parts: training data and test data. She gets the parameters of the model on training data and test the model on test data.
To her 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 will degrade to linear function if a = 0.
It's very easy to calculate the minimal error if there is only one test error curve. However, there are several datasets, which means Josephina will obtain many parabolic curves. Josephina wants to get the tuned parameters that make the best performance on all datasets. So she should take all error curves into account, i.e., she has to deal with many quadric functions and make a new error definition to represent the total error. Now, she focuses on the following new function's minimal which related to multiple quadric functions.
The new function F(x) is defined as follow:
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 to solve this problem. As a super programmer, can you help her?
The input contains multiple test cases. The first line is the number of cases T (T < 100). Each case 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 corresponding coefficients of a quadratic function.
For each test case, output the answer in a line. Round to 4 digits after the decimal point.
2 1 2 0 0 2 2 0 0 2 -4 2
0.0000 0.5000
綆鏄庨鎰忥細姹備竴鍫?span style="COLOR: red">寮鍙e悜涓?/span>鐨勪簩嬈″嚱鏁板湪[0,1000]鑼冨洿涓婂嚱鏁板兼渶澶у肩殑鏈灝忓箋?/pre>浜屾鍑芥暟鐨勫瓙闆嗕粛鐒朵負鍑稿嚱鏁幫紝鎵浠ュ彲浠ョ敤涓夊垎娉曟眰鏋佸箋傜簿搴﹀疄鍦ㄥ緢铔嬬柤錛岃繖棰樿姹傚煎煙綺劇‘鍒?e-4錛屼絾鏄畾涔夊煙娌¤綺劇‘鍒板灝戯紝緇撴灉姝粀a錛屽崱鍒?e-10緇堜簬榪囦簡銆傘?/pre>璐翠唬鐮?/pre>1# include <cstdio>
2# include <cmath>
3using namespace std;
4int n;
5int data[10001][3];
6# define max(a,b) ((a)>(b)?(a):(b))
7double cal(double mid)
8{
9double res=-1e26;
10for(int i=0;i<n;i++)
11res=max(res,data[i][0]*mid*mid+data[i][1]*mid+data[i][2]);
12return res;
13}
14int main()
15{
16int test;
17scanf("%d",&test);
18while(test--)
19![]()
{
20scanf("%d",&n);
21for(int i=0;i<n;i++)
22scanf("%d%d%d",&data[i][0],&data[i][1],&data[i][2]);
23double s=0.0,e=1000.0;
24double last=s;
25while(fabs(e-s)>1e-10)
26![]()
{
27![]()
28double m1=(s+e)/2.0,m2=(m1+e)/2.0;
29if(cal(m1)<cal(m2))
30e=m2;
31else
32s=m1;
33}
34printf("%.4lf\n",cal(e));
35}
36return 0;
37}
38
39
]]>