Error Curves

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 6241    Accepted Submission(s): 2341

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
 
题目的意思就是给出多个开口向上的一元二次方程,求出极大值的最小值,抛物线肯定是凸函数,直接三分就行了
#pragma GCC diagnostic error "-std=c++11"
#include<bits/stdc++.h>
#define _ ios_base::sync_whit_stdio(0);cin.tie(0); using namespace std;
const int N = + ;
const int INF = (<<);
const double eps = 1e-; double a[N], b[N], c[N];
int n; double fun(double x){
double res = - INF;
for(int i = ; i < n; i++)
res = max(res, a[i] * x * x + b[i] * x + c[i]);
return res;
} double ternary_search(double L, double R){
double mid1, mid2;
while(R - L > eps){
mid1 = ( * L + R) / ;
mid2 = (L + * R) / ;
if(fun(mid1) >= fun(mid2)) L = mid1;
else R = mid2;
}
return (L + R) * 0.5;
} int main(){
int T;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
for(int i = ; i < n; i++){
scanf("%lf %lf %lf", &a[i], &b[i], &c[i]);
}
double x = ternary_search(, );
printf("%.4f\n", fun(x));
}
}

HDU-3714 Error Curves(凸函数求极值)的更多相关文章

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

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

  2. hdu 3714 Error Curves(三分)

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

  3. HDU 3714 Error Curves

    Error Curves 思路:这个题的思路和上一个题的思路一样,但是这个题目卡精度,要在计算时,卡到1e-9. #include<cstdio> #include<cstring& ...

  4. hdu 3714 Error Curves(三分)

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

  5. nyoj 1029/hdu 3714 Error Curves 三分

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

  6. 三分 HDOJ 3714 Error Curves

    题目传送门 /* 三分:凹(凸)函数求极值 */ #include <cstdio> #include <algorithm> #include <cstring> ...

  7. HDU-4717 The Moving Points(凸函数求极值)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. Error Curves HDU - 3714

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

  9. HDU 3714/UVA1476 Error Curves

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

随机推荐

  1. White Lines

    D. White Lines 主要思路就是利用差分 对于行:如果在某一个点上,向右下角涂掉 k*k 的矩形能够使得新出现一行 "B" 那么就在这个点上 +1(这里的加 +1 需要利 ...

  2. #pragma once vs #ifndef

    最后编辑: 2019-11-20 #pragma once 是一个非标准但被广泛支持的预处理符号, 其主要作用是防止文件重复引入问题. 在头文件中,可以定义 #pragma once 或者 #ifnd ...

  3. 数据预测算法-ARIMA预测

    简介 ARIMA: AutoRegressive Integrated Moving Average ARIMA是两个算法的结合:AR和MA.其公式如下: 是白噪声,均值为0, C是常数. ARIMA ...

  4. [BZOJ3786] 星系探索(括号序列+Splay)

    3786: 星系探索 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 2191  Solved: 644[Submit][Status][Discuss ...

  5. 使用ElementUI创建项目

    从 0 开始搭建 element 项目 第一步,安装 Nodejs/NPM https://nodejs.org/zh-cn/download/ 下载安装即可! 第二步,安装 vue-cli 打开 c ...

  6. IDEA 无法显示项目目录结构解决

    不要去网上看什么乱七八糟的骚教程,一点用都没有.直接按下列步骤操作: 1. 关闭IDEA, 2. 然后删除项目文件夹下的.idea文件夹3. 重新用IDEA工具打开项目

  7. 【转载】Linux的五个查找命令

    原文:http://www.ruanyifeng.com/blog/2009/10/5_ways_to_search_for_files_using_the_terminal.html 最近,我在学习 ...

  8. jenkins入门-----(1)安装、配置

    Jenkins概念 Jenkins是一个开源的.可扩展的持续集成.交付.部署(软件/代码的编译.打包.部署)的基于web界面的平台.允许持续集成和持续交付项目,无论用的是什么平台,可以处理任何类型的构 ...

  9. shell初级-----处理用户输入

    命令行参数 读取参数 位置参数变量是标准的数字:$0是程序名,$1是第一个参数,$2,是第二个参数,直到第九个参数$9. 特殊的变量:$#表示参数个数,$?表示最后运行的命令的结束代码(返回值) 每个 ...

  10. 六、Java中一个key存多个value的MultiValueMap,一键多值

    一.MultiValueMap介绍,与map,HashMap相差不多 添加一个Key对应一个Value的:void add(K, V); 添加一个Key对应多个Value的:void add(K, L ...