HDU-3714 Error Curves(凸函数求极值)
Error Curves
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 6241 Accepted Submission(s): 2341
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?
1
2 0 0
2
2 0 0
2 -4 2
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(凸函数求极值)的更多相关文章
- LA 5009 (HDU 3714) Error Curves (三分)
Error Curves Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu SubmitStatusPr ...
- hdu 3714 Error Curves(三分)
Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 3714 Error Curves
Error Curves 思路:这个题的思路和上一个题的思路一样,但是这个题目卡精度,要在计算时,卡到1e-9. #include<cstdio> #include<cstring& ...
- hdu 3714 Error Curves(三分)
http://acm.hdu.edu.cn/showproblem.php?pid=3714 [题意]: 题目意思看了很久很久,简单地说就是给你n个二次函数,定义域为[0,1000], 求x在定义域中 ...
- nyoj 1029/hdu 3714 Error Curves 三分
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3714 懂了三分思想和F(x)函数的单调性质,这题也就是水题了 #include "stdio ...
- 三分 HDOJ 3714 Error Curves
题目传送门 /* 三分:凹(凸)函数求极值 */ #include <cstdio> #include <algorithm> #include <cstring> ...
- HDU-4717 The Moving Points(凸函数求极值)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Error Curves HDU - 3714
Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...
- HDU 3714/UVA1476 Error Curves
Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
随机推荐
- hdu 4451 Dressing 衣服裤子鞋 简单容斥
Dressing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- 【CF1263E】Editor(线段树,栈)
题意:有一个无限长度的文本编辑器,刚开始没有内容,光标在第一格,接下来有n个操作,操作可能有3种: 1.光标左移一格,如果已经在第一格则不动 2.光标右移一格 3.将当前光标所在格的字符改成输入的字符 ...
- G.subsequence 1(dp + 排列组合)
subsequence 1 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 You are ...
- R_Studio(学生成绩)数据相关性分析
对“Gary.csv”中的成绩数据进行统计量分析 用cor函数来计算相关性,method默认参数是用pearson:并且遇到缺失值,use默认参数everything,结果会是NA 相关性分析 当值r ...
- 关于Java 8 forEach
1. forEach and Map 1.1 通常这样遍历一个Map Map<String, Integer> items = new HashMap<>(); items.p ...
- ZooKeePer总汇
一.什么Zookeeper Zookeeper是一个分布式开源框架,提供了协调分布式应用的基本服务,它向外部应用暴露一组通用服务——分布式同步(Distributed Synchronization) ...
- is == 编码与解码
is 和 == 主要是数字和字符串的比较 1 区别: ==比较的是两边的值 is比较的是两边值的id id获取的方法 id() 2 小数据池: -5~256 3 字符串中特殊字符有id ...
- 【学习】SpringBoot之全局异常处理器
/** * 全局异常处理器 **/ @ControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(Exceptio ...
- echarts_02
1. 如果数据加载时间较长,一个空的坐标轴放在画布上也会让用户觉得是不是产生 bug 了,因此需要一个 loading 的动画来提示用户数据正在加载. ECharts 默认有提供了一个简单的加载动画. ...
- vue.js环境安装
1.到官网(http://nodejs.cn/download/)下载Node.JS运行环境并安装(由于现在的Node中自带npm包管理器,所以就不需要额外下载npm了) 2.如果是新手,那么建议以引 ...