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 ...
随机推荐
- 使用VSCODE开发UE4
完全可行,速度很快,智能提示.代码格式化.查找Symbol等等都不比VS+Visual AssistX 差. 准备 打开编辑器的Editor Preferences>Source Code,选择 ...
- [2019杭电多校第一场][hdu6582]Path(最短路&&最小割)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6582 题意:删掉边使得1到n的最短路改变,删掉边的代价为该边的边权.求最小代价. 比赛时一片浆糊,赛后 ...
- Oracle 监听hang住
1.数据库正常启动: [oracle@db ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Sat Aug 24 ...
- getFieldDecorator用法(一)——登录表单
之前使用antd的ui表单,却没发现这么好用的用法,推荐给大家 import React from "react"; import { Card, Form, Input, But ...
- Linux下不同组件运行命令
Spark优化配置 添加外包路径 1.1 vim $SPARK_HOME/conf/spark-defaults.conf spark.executor.extraClassPath file:/// ...
- jQuery实现表单动态添加与删除数据操作示例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&q ...
- java期末总结
java期末总结: java语言特点:1.简洁有效 2.可移植性 3.面向对象 4.解释型 5.适合分布式计算 6.拥有较好的性能 7.健壮.防患于未然 8.具有多线程处理能力 9.具有较高的安全性 ...
- 使用C#语言,将DataTable 转换成域模型
DataTable dt = SqlHelper.Query(strQuery); ) * size).Take(pagesize); List<Model> listData = new ...
- wls12C启用Gzip
https://community.oracle.com/message/14109820 https://docs.oracle.com/middleware/1221/wls/NOTES/what ...
- linux (一)
一.文件目录 cd 目录进出 pwd 查看路径 ls:ll 查看目录 mkdir : mkdir -p app/test 创建目录 touch 创建文件 rm :rm -r 递归 -f 强制 mv ...