HDU 3714 Error Curves

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3714


Error Curves Time limit:4000/2000 MS (java/others) Memory limit:65536/65536 K (java/others)Total submission (s): 4536 Accepted Submission (s): 1721

problem DescriptionJosephina 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? 
InputThe 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. 
Outputfor 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
 
AuthorLIN, Yue 
SourceAsia Chengdu Regional Contest 
recommendZhouzeyong
idea: Single-peak function to find the extremum problem. Three-part definition field [0,1000], solve the answer. Note: Precision cards are more stringent.
directly attach the AC code:
#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 localfreopen ("Input.txt", "R", stdin), Freopen ("Output.txt", "w", stdout), #endifint 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);d ouble l=0.0, r=1000.0, M ID, tri;while (r-l > EPs) {mid = (r+l)/2.0;tri = (r+mid)/2.0;if (func (Mid) > func (tri)) L = Mid;elser = tri;} Double ans = func (l);p rintf ("%.4f\n", ans); return 0;}

HDU 3714 Error Curves

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.