La 5009 (HDU 3714) error curves (3 points)

Source: Internet
Author: User

A-error curves Time limit:3000 Ms Memory limit:0 KB 64bit Io format:% LLD & % llusubmitstatuspracticeuvalive 5009 appoint description:

Description

Joseph Ina is a clever girl and addicted to machine learning recently. She pays much attention to a method called linear discriminant analysis, which has interesting properties.

In order to test the algorithm's efficiency, she collects collect 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 formF (x) = ax2 + bx + c. The Quadratic will degrade to linear function ifA = 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 Joseph ina will obtain extends parabolic curves. joseph ina wants to get the tuned parameters that make the best performance on all datasets. so she shoshould take all error curves into account, I. E ., she has to deal with your 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 functionF (x)Is defined as follow:

F (x) = max (SI (x )),I= 1...N. The domainXIt is [0, 1000].Si (X)Is a quadric function.

Joseph ina wonders the minimumF (x). Unfortunately, it's too hard for her to 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 casesT(T<100). Each case begins with a numberN(N≤ 10000). FollowingNLines, each line contains three IntegersA(0 ≤A≤ 100 ),B(|B| ≤ 5000 ),C(|C| ≤ 5000), which mean the corresponding coefficients of a quadratic function.

Output

For each test case, output 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



A lot of parabolic f (I) A [I], B [I], C [I], defined f (I) = max (f (I), calculate the minimum value of f (x) in the range.


Solution: because a> = 0 is given in the question, A may be zero, and the curve is a straight line. Otherwise, the curve is a parabolic open up, so it is a lower convex function, therefore, f (x) is also a subconvex function. Therefore, the extreme values of f (x) can be obtained by using the three-way method. First, calculate the specific value of f (x), and then you can directly calculate the three points. For details, see the code.





AC code:

# Include <cstdio> # include <algorithm> using namespace STD; const int maxn = 10000 + 10; int n, a [maxn], B [maxn], C [maxn]; double F (Double X) {// evaluate f (x) Double ans = A [0] * x + B [0] * x + C [0]; for (INT I = 1; I <n; I ++) {ans = max (ANS, A [I] * x + B [I] * x + C [I]);} return ans;} int main () {// freopen ("in.txt ", "r", stdin); int t; scanf ("% d", & T); While (t --) {scanf ("% d", & N ); for (INT I = 0; I <n; I ++) scanf ("% d", & A [I], & B [I], & C [I]); double L = 0, r = 1000; // returns an extreme value for (INT I = 0; I <100; I ++) {double mid = L + (R-l)/3; double midmid = r-(R-l)/3; if (f (MID) <F (midmid )) R = midmid; else l = mid;} printf ("%. 4lf \ n ", F (l);} return 0 ;}


La 5009 (HDU 3714) error curves (3 points)

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.