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. 使用ClassLoader类装载器获取系统资源

    使用ClassLoader类装载器获取系统资源 2010-05-11 16:19:39 分类: Java /* ClassLoader 有两种方法获得系统资源,一个种静态方法,一种是实例方法. 静态方 ...

  2. insmod: error inserting &#39;hello.ko&#39;: -1 Invalid module format

    在学习编写linux驱动程序的时候,一般都是从写一个helloworld的模块開始. 可是在编译完毕后,进行模块载入的时候,有时会出现例如以下错误: insmod: error inserting ' ...

  3. Codeforces Gym 100015F Fighting for Triangles 状态压缩DP

    F Fighting for Triangles Description Andy and Ralph are playing a two-player game on a triangular bo ...

  4. 风暴英雄 http 302重定向 正在等待游戏模式下载完成

    抓包 在抓到的数据包里面,看到一个http get请求,右键选中,然后follow stream wireshark自动进行数据包过滤tcp.stream eq 1340,并且可以看到完整的数据通讯 ...

  5. 【转】小白级的CocoaPods安装和使用教程

    原文网址:http://www.jianshu.com/p/e2f65848dddc 百度有很多CocoaPods的安装教程.第一次看的时候,确实有点摸不透的感觉.经过思考,一步一步来实践,前后花了三 ...

  6. 更改python字符编码以便使用UTF-8的编码url路径

    url编码分两种, 一种是unicode, 另一种是gb2312, 今天遇到的一个网站是要将字符编码按照gb2312来编码,用来得到一个先填写blanks后再返回页面的数据,废话少说,需要做的就是先查 ...

  7. python初始面向对象

    阅读目录 楔子 面向过程vs面向对象 初识面向对象 类的相关知识 对象的相关知识 对象之间的交互 类命名空间与对象.实例的命名空间 类的组合用法 初识面向对象小结 面向对象的三大特性 继承 多态 封装 ...

  8. caffe mnist实例 --lenet_train_test.prototxt 网络配置详解

    1.mnist实例 ##1.数据下载 获得mnist的数据包,在caffe根目录下执行./data/mnist/get_mnist.sh脚本. get_mnist.sh脚本先下载样本库并进行解压缩,得 ...

  9. Exception异常常见属性

    废话少说,直接上代码: try { int n = Convert.ToInt32("@"); } catch(Exception ex) { Console.WriteLine( ...

  10. Android Studio 一些注意事项(自用,不定期更新)

    1,Android Studio 版本的选择 写这篇的时候,官方版本已经到了 v3.2.0,而我习惯使用的版本是 v2.3.1,因为这个版本有自带sdk的安装版,比较方便, 同时,v2.3.1 新建项 ...