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 ...
随机推荐
- Java回调
最近在看Spring的JdbcTemplate,有碰到很多的回调场景,在这里做一个笔记. 示例: 公司的经理出差时打电话给你让你帮他处理件事情,但不能一直通着电话,于是他让你办好事情后打电话告诉他一声 ...
- [CSP-S模拟测试]:小Y的图(最小生成树+LCA)
题目传送门(内部题131) 输入格式 第一行三个整数$n$.$m$和$Q$. 接下来$m$行每行三个整数$x$.$y$.$z$($1\leqslant x,y\leqslant n,1\leqslan ...
- Redis Cluster in Ubuntu
1. 首先,进到Redis-server 的位置,确认 Redis server 可以正常启动 2. 在 redis-5.0.3 目录下创建文件夹 redisCluster_Demo_byMe,并在 ...
- Vue CLi3入门
摘自:https://www.jianshu.com/p/cf9b56efd3b8 Vue CLi3入门 12018.11.15 14:16:17字数 1222阅读 8895 地址 Vue CLi3 ...
- java链接Mysql出现警告:Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by
Java使用mysql-jdbc连接MySQL出现如下警告: Establishing SSL connection without server's identity verification is ...
- 191028DjangoORM之多表操作
一.多表操作之一对多 models.py from django.db import models class Book(models.Model): name = models.CharField( ...
- bootstrap 学习笔记(部分)
这个课程中的boostrap是3.0+版本的.(2.0与3.0有区别) bootstrap中的JS是依赖于jquery的,所以需要事先引用jquery(1.9.0版本以上). <!DOCTYPE ...
- UVA 816 -- Abbott's Revenge(BFS求最短路)
UVA 816 -- Abbott's Revenge(BFS求最短路) 有一个 9 * 9 的交叉点的迷宫. 输入起点, 离开起点时的朝向和终点, 求最短路(多解时任意一个输出即可).进入一个交叉 ...
- 全面解读php-函数
一.静态变量 二.函数的参数 三.函数的引用返回 四.外部文件的导入 五.内置函数 1.时间日期函数 2.IP处理函数 3.打印函数: 分类 函数名 说明 语言结构 print() 只能打印一个变量 ...
- 浏览器端-W3School-HTML:HTML DOM Select 对象
ylbtech-浏览器端-W3School-HTML:HTML DOM Select 对象 1.返回顶部 1. HTML DOM Select 对象 Select 对象 Select 对象代表 HTM ...