HDOJ 3714
題目意思很難得懂,給N個2次函數,求最大值中的最小值
3分法 ?(用黃金分割比例可以省去一次計算使速度更快)用CIN COUT會超時
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.
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?
InputThe 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.
OutputFor each test case, output the answer in a line. Round to 4 digits after the decimal point.
Sample Input2
1
2 0 0
2
2 0 0
2 -4 2
Sample Output0.0000
0.5000
AuthorLIN, Yue
Source2010 Asia Chengdu Regional Contest
#include <cstdio>#include <iostream>#include <cmath>
#define eps 1e-9
using namespace std;
int a[10030],b[10030],c[10030]; ? int n;double s,m1,m2,e;
double qua(int a,int b,int c,double x){return a*x*x+b*x+c;}
int main(){int T;scanf("%d",&T);while(T--){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d%d%d",&a,&b,&c);}
s=0.;e=1001.;while(e-s>eps){// ? ? ? ?cout<<s<<"...."<<e<<endl;m1=(s*2+e)/3.;m2=(s+2*e)/3.;
double min1=-999999999,min2=-999999999;for(int i=0;i<n;i++){double ans1=qua(a,b,c,m1);double ans2=qua(a,b,c,m2);min1=max(min1,ans1);min2=max(min2,ans2);}
if(min2>=min1){e=m2;}else{s=m1;}
}double ans=-99999999;for(int i=0;i<n;i++){ans=max(ans,qua(a,b,c,e));}printf("%.4lf\n",ans);}
return 0;}?
3分法 ?(用黃金分割比例可以省去一次計算使速度更快)用CIN COUT會超時
Error Curves
Time Limit : 4000/2000ms (Java/Other)???Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : ? ?Accepted Submission(s) :?
Problem DescriptionJosephina is a clever girl and addicted to Machine Learning recently. Shepays 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.
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?
InputThe 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.
OutputFor each test case, output the answer in a line. Round to 4 digits after the decimal point.
Sample Input2
1
2 0 0
2
2 0 0
2 -4 2
Sample Output0.0000
0.5000
AuthorLIN, Yue
Source2010 Asia Chengdu Regional Contest
#include <cstdio>#include <iostream>#include <cmath>
#define eps 1e-9
using namespace std;
int a[10030],b[10030],c[10030]; ? int n;double s,m1,m2,e;
double qua(int a,int b,int c,double x){return a*x*x+b*x+c;}
int main(){int T;scanf("%d",&T);while(T--){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d%d%d",&a,&b,&c);}
s=0.;e=1001.;while(e-s>eps){// ? ? ? ?cout<<s<<"...."<<e<<endl;m1=(s*2+e)/3.;m2=(s+2*e)/3.;
double min1=-999999999,min2=-999999999;for(int i=0;i<n;i++){double ans1=qua(a,b,c,m1);double ans2=qua(a,b,c,m2);min1=max(min1,ans1);min2=max(min2,ans2);}
if(min2>=min1){e=m2;}else{s=m1;}
}double ans=-99999999;for(int i=0;i<n;i++){ans=max(ans,qua(a,b,c,e));}printf("%.4lf\n",ans);}
return 0;}?
轉載于:https://www.cnblogs.com/CKboss/archive/2013/04/25/3351085.html
總結
- 上一篇: 网络字节与主机字节转换 htons(),
- 下一篇: DBCC收缩数据库