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

题意

  给定n条二次曲线S(x),定义F(x)=max(Si(x)), 求出F(x)在0~1000上的最小值。

题解:

  三分基础题,三分下凸。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long ll;
const int N = + ;
int T,a[N],b[N],c[N],n;
double f(double x) {
double ans = a[] * x * x + b[] * x + c[];
for(int i = ; i <= n; i++) {
ans = max(ans, a[i] * x * x + b[i] * x + c[i]);
}
return ans;
}
double three_search(double l,double r) {
for(int i = ;i < ; i++) {
double mid = l + (r - l) / ;
double mid2 = r - (r - l) / ;
if(f(mid) > f(mid2)) l = mid;
else r = mid2;
}
return f(l);
}
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(int i = ; i <= n; i++) scanf("%d%d%d",&a[i],&b[i],&c[i]);
double ans = three_search(,);
printf("%.4f\n",ans);
}
return ;
}

UVA - 1476 Error Curves 三分的更多相关文章

  1. UVA 1476 - Error Curves(三分法)

    UVA 1476 1476 - Error Curves 题目链接 题意:给几条下凹二次函数曲线.然后问[0,1000]全部位置中,每一个位置的值为曲线中最大值的值,问全部位置的最小值是多少 思路:三 ...

  2. 【单峰函数,三分搜索算法(Ternary_Search)】UVa 1476 - Error Curves

    Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...

  3. uva 1476 - Error Curves

    对x的坐标三分: #include<cstdio> #include<algorithm> #define maxn 10009 using namespace std; do ...

  4. UVA 5009 Error Curves

    Problem Description Josephina is a clever girl and addicted to Machine Learning recently. She pays m ...

  5. nyoj 1029/hdu 3714 Error Curves 三分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3714 懂了三分思想和F(x)函数的单调性质,这题也就是水题了 #include "stdio ...

  6. hdu 3714 Error Curves(三分)

    http://acm.hdu.edu.cn/showproblem.php?pid=3714 [题意]: 题目意思看了很久很久,简单地说就是给你n个二次函数,定义域为[0,1000], 求x在定义域中 ...

  7. UVALive 5009 Error Curves 三分

    //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include& ...

  8. LA 5009 (HDU 3714) Error Curves (三分)

    Error Curves Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu SubmitStatusPr ...

  9. hdu 3714 Error Curves(三分)

    Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

随机推荐

  1. UVALive 6663 Count the Regions 离散+bfs染色_(:зゝ∠)_

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4675">点击打开链接 gg.. ...

  2. Bash脚本中的操作符

    一.文件測试操作符 假设以下的条件成立将会返回真. -e 文件存在 -a 文件存在 这个选项的效果与-e同样. 可是它已经被"弃用"了, 而且不鼓舞使用. -f 表示这个文件是一个 ...

  3. Android学习之——优化篇(1)

    一.优化的品质 1.简练.2.可读性强.3.模块化:4.层次性:5.设计良好.6.高效.7.优雅:8.清晰. 二.常见的编程规范     1. 基本要求 · 结构清晰,简单易懂.单个函数不超过100行 ...

  4. BZOJ3170: [Tjoi2013]松鼠聚会

    [传送门:BZOJ3170] 简要题意: 给出n个点的坐标,规定两个点的距离=max(|x1-x2|,|y1-y2|) 要求选出一个点,使得这个点到所有点的距离和最小 题解: 切比雪夫转换例题 将一个 ...

  5. hdoj--5532--Almost Sorted Array(正反LIS)

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  6. Jquery validform

    一.validform是什么?            validform是一款智能的表单验证js插件,它是基于jQuery库与css,我们只需要把表单对象放入,             就可以对整个表 ...

  7. 修改eclipse最近访问的工程的配置文件

    此文件为:org.eclipse.ui.ide.prefs 配置项为:RECENT_WORKSPACES= 示例:RECENT_WORKSPACES=E\:\\Workspaces\\wokspace ...

  8. 深度理解DOM事件(实例)

    前言 通过如下两个实例来理解DOM事件 实例1--点击别处关闭浮层 onclick与addEventListener的区别 实例2--点击后颜色一层一个层出现的漂亮的彩虹圈 1  实例1--点击别处关 ...

  9. c++标准库都有哪些文件

    from:http://topic.csdn.net/u/20090201/16/3bd41b72-5694-474e-a68b-98b2f070e76b.html C++标准库的所有头文件都没有扩展 ...

  10. Hibernate配置文件 hibernate.cfg.xml

    <!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--> <?xml version='1.0' ...