UVA 5009 Error Curves
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?
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.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
double eps=1e-;
double a[],b[],c[];
int n;
double cal(double x)
{int i;
double tmp=a[]*x*x+b[]*x+c[];
for (i=;i<=n;i++)
{
tmp=max(tmp,a[i]*x*x+b[i]*x+c[i]);
}
return tmp;
}
int main()
{int T,i;
cin>>T;
while (T--)
{
cin>>n;
for (i=;i<=n;i++)
{
scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);
}
int t=;
double l=,r=,ans=;
while (t--)
{
double mid1=l+(r-l)/3.0,mid2=r-(r-l)/3.0;
if (cal(mid1)<cal(mid2)) r=mid2;
else l=mid1;
}
printf("%.4lf\n",cal(l));
}
}
最新文章
- SCVMM中Clone虚拟机失败显示Unsupported Cluster Configuration状态
- [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素
- python网络编程【四】(域名系统)
- ubuntu15.10 或者 16.04 或者 ElementryOS 下使用 Dotnet Core
- 南洋理工 OJ 115 城市平乱 dijstra算法
- WCF配置文件全攻略
- Python Unittest 自动化单元测试框架Demo
- tomcat实现多端口、多域名访问
- C#中的集合类——HashTable
- Memcache(1)
- javascript模板引擎template.render使用
- for和getElementByTagName配合
- 深入分析Android动画(二)
- 怎么用Mac电脑创建多个桌面
- uni-app (1) 安装与运行。
- BZOJ3881 Divljak
- 【下一代核心技术DevOps】:(七)持续集成Jenkins的应用(Aliyun Pipiline持续构建)
- Centos7.3+uwsgi+Nginx部署Django程序
- 【MLP】多层感知机网络
- Guava Files 源码分析(二)