• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            The 2010 ACM-ICPC Asia Chengdu Regional Contest Error Curves 三分法求凸函數極值

            Error Curves

            Time Limit: 2 Seconds      Memory Limit: 65536 KB

            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.

            Quadric Function

            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?

            Input

            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.

            Output

            For each test case, output the answer in a line. Round to 4 digits after the decimal point.

            Sample Input

            2
            1
            2 0 0
            2
            2 0 0
            2 -4 2
            

            Sample Output

            0.0000
            0.5000
            
            簡明題意:求一堆開口向上的二次函數在[0,1000]范圍上函數值最大值的最小值。
            二次函數的子集仍然為凸函數,所以可以用三分法求極值。精度實在很蛋疼,這題要求值域精確到1e-4,但是定義域沒說精確到多少,結果死wa,卡到1e-10終于過了。。
            貼代碼
             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{
             9   double res=-1e26;
            10   for(int i=0;i<n;i++)
            11     res=max(res,data[i][0]*mid*mid+data[i][1]*mid+data[i][2]);
            12   return res;
            13}

            14int main()
            15{
            16    int test;
            17    scanf("%d",&test);
            18    while(test--)
            19    {
            20       scanf("%d",&n);
            21       for(int i=0;i<n;i++)
            22         scanf("%d%d%d",&data[i][0],&data[i][1],&data[i][2]);
            23       double s=0.0,e=1000.0;
            24       double last=s;
            25       while(fabs(e-s)>1e-10)
            26       {
            27       
            28         double m1=(s+e)/2.0,m2=(m1+e)/2.0;
            29         if(cal(m1)<cal(m2))
            30           e=m2;
            31         else 
            32           s=m1;
            33       }

            34       printf("%.4lf\n",cal(e));
            35    }

            36    return 0;
            37}

            38
            39

            posted on 2010-11-16 00:50 yzhw 閱讀(800) 評論(0)  編輯 收藏 引用 所屬分類: numberic

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            公告

            統計系統

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久香蕉国产线看观看99| 偷偷做久久久久网站| 久久97精品久久久久久久不卡| 国产精品一区二区久久| 久久99精品久久久久久水蜜桃| 99久久精品免费看国产一区二区三区 | 久久se精品一区精品二区国产| 欧美久久综合九色综合| 久久精品国产99久久久| 久久久无码精品亚洲日韩软件| 色综合久久综合中文综合网| 国产精自产拍久久久久久蜜| 亚洲欧美成人综合久久久| 97精品国产97久久久久久免费| 伊人色综合久久天天人手人婷| 久久福利青草精品资源站| 三级三级久久三级久久| 国产精品亚洲美女久久久| 久久青青草原亚洲av无码app| 亚洲美日韩Av中文字幕无码久久久妻妇| 亚洲国产精品无码久久一线| 久久伊人影视| 亚洲一区中文字幕久久| 国内精品久久久久久久97牛牛| 色偷偷88欧美精品久久久| 国产精品亚洲综合专区片高清久久久| 久久午夜羞羞影院免费观看| 国产亚洲精品久久久久秋霞| 午夜精品久久久久久影视777| 久久93精品国产91久久综合| 94久久国产乱子伦精品免费| 日韩一区二区久久久久久 | 色婷婷久久久SWAG精品| 99久久国产热无码精品免费久久久久| 久久精品无码午夜福利理论片 | 狠狠色丁香久久婷婷综| 2021少妇久久久久久久久久| 成人久久久观看免费毛片| 狠色狠色狠狠色综合久久| 嫩草影院久久99| 国产精品久久久天天影视香蕉|