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 ...
随机推荐
- Unity3D_(API)Random随机数
Unity随机数Random官方文档: 传送门 一.生成一个随机数 二.Random.InitState()生成伪随机数 三.官方文档中常用的方法 创建一个Cube用来挂载Random_Gary.cs ...
- R_Studio(关联)对Groceries数据集进行关联分析
RGui的arules程序包里含有Groceries数据集,该数据集是某个杂货店一个月真实的交易记录,共有9835条消费记录,169个商品 #install.packages("arules ...
- R_Studio(教师经济信息)逻辑回归分析的方法和技巧
使用R语言对"教师经济信息"进行逻辑回归分析 (1)按3:1的比例采用简单随机抽样方法,创建训练集和测试集 (2)用训练集创建逻辑回归模型 (3)用测试集预测贷款结果,并用tabl ...
- [CSP-S模拟测试]:午餐(贪心+最短路)
题目传送门(内部题115) 输入格式 第一行两个正整数$n,m$. 接下来$m$行,每行$4$个正整数$u_j,v_j,L_j,R_j$. 接下来一行$n$个数,若第$i$个数为$1$,则$i$号同学 ...
- C++入门经典-例3.3-if-else语句的奇偶性判别
1:代码如下: // 3.3.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using ...
- ES6 字符串的扩展(待细读)
1.确定字符串中是否含有某个字符串 indexof(value,num):可返回某个指定的字符串值在字符串中首次出现的位置.ES5方法,num范围(0~length-1) includes(value ...
- .slideUp()
.slideUp() Effects > Sliding .slideUp( [duration ] [, complete ] )Returns: jQuery Description: Hi ...
- The 5 types of programmers
from: http://stevenbenner.com/2010/07/the-5-types-of-programmers/ps: 评论也很精彩 In my code journeys and ...
- js 外部引用文件与 onload()函数的优先级
在HTML页面中的body加载进来的时候,外部引用的js文件存放的位置 1.js文件放在body里面,则是按照body的加载顺序(按先后顺序)进行加载 2.js文件放在<head>标签里面 ...
- 八、MD5加密并封装,并调用封装方法
一.MD5加密 封装Md5 public class Md5 { //十六进制下数字到字符的映射数组 private static final char hexDigits[] = { '0', '1 ...