HDU3714 Error Curves (single-peak function)

Source: Internet
Author: User

Calculate the minimum value of F (x) on [] for n quadratic functions Si (x), F (x) = max {Si (x. S (x) = ax ^ 2 + bx + c (0 <= a <= 100, | B |, | c | <= 5000) after a simple analysis, we can see that the image of function F (x) is a subconvex function. You can use the three-way method to obtain the greatest value. 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) {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 () {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.0, R = 1000.0; for (int I = 0; I <100; ++ I) {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;} The Extreme Value of the single-peak function can also be obtained by golden division.

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.