Uva5009 Error Curves

已知n条二次曲线si(x) = ai*x^2 + bi*x + ci(ai ≥ 0),定义F(x) = max{si(x)},求出F(x)在[0,1000]上的最小值.

链接:传送门

分析:最大值最小,我们可以利用二分来解,但是有一个更牛的方法叫:“三分法”,这个方法的应用范围是凸函数,可以看一个图像:

L和R是边界,m1,m2是三等分点,如果f(m1) < f(m2),那么最小值肯定在[l,m2]内,注意,不是[l,m1]因为如果m1在最低点右边,那么就会矛盾,同理,如果f(m2) < f(m1),那么最小值肯定在[m1,r]之间,剩下的操作和二分法基本上就是一样的了。

对于本题而言,可以看出也是一个凸函数,所以我们可以利用三分法来快速求最小值.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<map>
#include<string>

using namespace std;

const int maxn = 10010;

int n, a[maxn], b[maxn], c[maxn],t;

double f(double x)
{
    double ans = a[1] * x * x + b[1] * x + c[1];
    for (int i = 2; i <= n; i++)
        ans = max(ans, a[i] * x*x + b[i] * x + c[i]);
    return ans;
}

int main()
{
    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.0, R = 1000.0;

        while (R - L > 0.000000001)
        {
            double m1 = L + (R - L) / 3, m2 = R - (R - L) / 3;
            if (f(m1) < f(m2))
                R = m2;
            else
                L = m1;
        }

        printf("%.4lf\n", f(L));
    }

    return 0;
}
时间: 2024-11-05 15:51:37

Uva5009 Error Curves的相关文章

UVA - 1476 Error Curves 三分

                                       Error Curves 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

hdu3714 Error Curves

题目: Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1151    Accepted Submission(s): 440 Problem Description Josephina is a clever girl and addicted to Machine Learning recently. She

三分 HDOJ 3714 Error Curves

题目传送门 1 /* 2 三分:凹(凸)函数求极值 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 using namespace std; 9 10 const int MAXN = 1e4 + 10; 11 const int INF = 0x3f3f3f3f; 12 const double EPS = 0.0000000

LA 5009 (HDU 3714) Error Curves (三分)

A - Error Curves Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu SubmitStatusPracticeUVALive 5009 Appoint description: Description Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a

Error Curves(2010成都现场赛题)

F - Error Curves Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a method called Linear Discriminant Analysis, which h

HDU 3714 Error Curves

题目链接: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 Description Josephina is a clever g

UVA 1476 - Error Curves(三分法)

UVA 1476 1476 - Error Curves 题目链接 题意:给几条下凹二次函数曲线,然后问[0,1000]所有位置中,每个位置的值为曲线中最大值的值,问所有位置的最小值是多少 思路:三分法,由于都是下凹函数,所以所有曲线合并起来,仍然是一个下凹函数,满足单峰,用三分求极值 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using na

UVALive 5009 Error Curves 三分

//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<climits

HDU-3714 Error Curves(凸函数求极值)

Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 6241    Accepted Submission(s): 2341 Problem Description Josephina is a clever girl and addicted to Machine Learning recently. Shepay