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

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?

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
画图理解一下,
几个下凸函数取max仍然是下凸函数
然后三分就行了
 #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));
}
}

最新文章

  1. SCVMM中Clone虚拟机失败显示Unsupported Cluster Configuration状态
  2. [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素
  3. python网络编程【四】(域名系统)
  4. ubuntu15.10 或者 16.04 或者 ElementryOS 下使用 Dotnet Core
  5. 南洋理工 OJ 115 城市平乱 dijstra算法
  6. WCF配置文件全攻略
  7. Python Unittest 自动化单元测试框架Demo
  8. tomcat实现多端口、多域名访问
  9. C#中的集合类——HashTable
  10. Memcache(1)
  11. javascript模板引擎template.render使用
  12. for和getElementByTagName配合
  13. 深入分析Android动画(二)
  14. 怎么用Mac电脑创建多个桌面
  15. uni-app (1) 安装与运行。
  16. BZOJ3881 Divljak
  17. 【下一代核心技术DevOps】:(七)持续集成Jenkins的应用(Aliyun Pipiline持续构建)
  18. Centos7.3+uwsgi+Nginx部署Django程序
  19. 【MLP】多层感知机网络
  20. Guava Files 源码分析(二)

热门文章

  1. Alpha冲刺博客集
  2. 冲刺NO.11
  3. java封装的概念
  4. android 检查软件是否有更新版本
  5. decltype操作符
  6. Step by Step 真正从零开始,TensorFlow详细安装入门图文教程!帮你完成那个最难的从0到1
  7. GIT的安装及命令使用
  8. 你考虑清楚了吗就决定用 Bootstrap ?
  9. Python之面向对象四
  10. 喜马拉雅音频下载工具 - xmlyfetcher