首页 > ACM题库 > HDU-杭电 > HDU 3714-Error Curves-图-[解题报告]HOJ
2015
02-21

HDU 3714-Error Curves-图-[解题报告]HOJ

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 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.

Double Maze

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 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 to solve this problem. As a super programmer, can you help her?

输入:

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.

输出:

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.

样例输入:

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

样例输出:

0.0000
0.5000

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

【题意】:

  题目意思看了很久很久,简单地说就是给你n个二次函数,定义域为[0,1000], 求x在定义域中每个x所在的n个函数的最大值的最小值。很拗口吧,显然这题不是组队或者耐心的做是不知道性质的,至少我没看出来。网上说是三分,我画了几个图,确实是。根据二次函数的性质,增长的快慢已经确定了,那的确是单峰的。那就OK了。另外eps的问题1e-8还是wa,1e-9AC。想了下,因为有系数a,b,c的缘故,一乘就WA了。代码就是三分了,没什么特殊的。(三分,什么时候我能主动的看出你???)

【题解】:

  第二个三分,三分啊三分,很难自己看出来啊!!!

【code】:

  

 #include <iostream>
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
 
 using namespace std;
 
 #define eps 1e-9
 #define INF 1e15
 
 struct Nod
 {
     double a,b,c;
 }node[10010];
 
 int n;
 
 double func(double a,double b,double c,double x)
 {
     return a*x*x+b*x+c;
 }
 
 double getMins(double x)
 {
     int i;
     double maks = -INF;
     for(i=0;i<n;i++)
     {
         double temp = func(node[i].a,node[i].b,node[i].c,x);
         if(maks<temp)
         {
             maks = temp;
         }
     }
     return maks;
 }
 
 void sanfen()
 {
     double l=0,r=1000,mid,ans = INF;
     while(l<=r)
     {
         mid = (l+r)/2;
         double temp1 = getMins(mid);
         double temp2 = getMins(mid-eps);
         if(temp1<temp2)
         {
             l = mid + eps;
         }
         else
         {
             r = mid - eps;
         }
         if(ans>temp1)
         {
             ans=temp1;
         }
     }
     printf("%.4lf\n",ans);
 }
 
 int main()
 {
     int t;
     scanf("%d",&t);
     while(t--)
     {
         scanf("%d",&n);
         int i;
         for(i=0;i<n;i++)
         {
             scanf("%lf%lf%lf",&node[i].a,&node[i].b,&node[i].c);
         }
         sanfen();
     }
     return 0;
 }

 

 

 

参考:http://www.cnblogs.com/crazyapple/archive/2013/09/12/3317755.html


,