UVA - 1476 Error Curves 三分
Error Curves
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 minimal which related to
multiple quadric functions.
The new function F(x) is defined as follow:
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
题意 :
给定n条二次曲线S(x),定义F(x)=max(Si(x)), 求出F(x)在0~1000上的最小值。
题解:
三分基础题,三分下凸。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long ll;
const int N = + ;
int T,a[N],b[N],c[N],n;
double f(double x) {
double ans = a[] * x * x + b[] * x + c[];
for(int i = ; i <= n; i++) {
ans = max(ans, a[i] * x * x + b[i] * x + c[i]);
}
return ans;
}
double three_search(double l,double r) {
for(int i = ;i < ; i++) {
double mid = l + (r - l) / ;
double mid2 = r - (r - l) / ;
if(f(mid) > f(mid2)) l = mid;
else r = mid2;
}
return f(l);
}
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(int i = ; i <= n; i++) scanf("%d%d%d",&a[i],&b[i],&c[i]);
double ans = three_search(,);
printf("%.4f\n",ans);
}
return ;
}
UVA - 1476 Error Curves 三分的更多相关文章
- UVA 1476 - Error Curves(三分法)
UVA 1476 1476 - Error Curves 题目链接 题意:给几条下凹二次函数曲线.然后问[0,1000]全部位置中,每一个位置的值为曲线中最大值的值,问全部位置的最小值是多少 思路:三 ...
- 【单峰函数,三分搜索算法(Ternary_Search)】UVa 1476 - Error Curves
Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...
- uva 1476 - Error Curves
对x的坐标三分: #include<cstdio> #include<algorithm> #define maxn 10009 using namespace std; do ...
- UVA 5009 Error Curves
Problem Description Josephina is a clever girl and addicted to Machine Learning recently. She pays m ...
- nyoj 1029/hdu 3714 Error Curves 三分
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3714 懂了三分思想和F(x)函数的单调性质,这题也就是水题了 #include "stdio ...
- hdu 3714 Error Curves(三分)
http://acm.hdu.edu.cn/showproblem.php?pid=3714 [题意]: 题目意思看了很久很久,简单地说就是给你n个二次函数,定义域为[0,1000], 求x在定义域中 ...
- UVALive 5009 Error Curves 三分
//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include& ...
- 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 ...
随机推荐
- 2014秋C++ 第7周项目 数据类型和表达式
课程主页在http://blog.csdn.net/sxhelijian/article/details/39152703,课程资源在云学堂"贺老师课堂"同步展示,使用的帐号请到课 ...
- How do I UPDATE from a SELECT in SQL Server?
方法1 https://stackoverflow.com/questions/2334712/how-do-i-update-from-a-select-in-sql-server UPDATE T ...
- Request.QueryString["id"] 、Request.Params["id"] 的强大
<form> <input type="text" name="id" value="值"> </form&g ...
- C++之易混淆知识点五
一.解析类继承中父类与子类之间成员的访问可见度: 外部可见度:指的是被子类继承的父类成员在子类的外部访问控制度,有protected.public.private. 内部可见度:指的是被子类继承的父类 ...
- 利用 js 获取地址栏参数
1.aspx页面,进行页面跳转 window.location.href = "ProviderInfo.aspx?ProviderID="+ProviderID; 2.Provi ...
- 【转】javascript 小数乘法结果错误处理
一.用js计算 12.32 * 7 结果是多少? 答案:86.24000000000001 为什么会出现这种问题?怎么解决? js在处理小数的乘除法的时候有一个bug,解决的方法可以是:将小数变 ...
- Windows下安装XAMPP,Wordpress
配置XAMPP: 1.下载:https://www.apachefriends.org/zh_cn/download.html(下载速度日了狗!) 2.安装XAMPP; 3.启动apache, ...
- Vue学习之路第六篇:v-on
v-on指令用来触发页面事件的指令. <body> <div id="app"> <button v-on:click="show()&qu ...
- 代理上网环境配置docker私有库
最后更新时间:2018年12月27日 Docker使用代理上网去 pull 各类 images,需要做如下配置: 创建目录: /etc/systemd/system/docker.service.d ...
- HTML 编码规范
语法 使用 4 个空格做为一个缩进层级,不允许使用 2 个空格或 tab 字符 在属性上,使用双引号 "",不要使用单引号 '' 属性名 / 属性值全小写,用中划线 - 做分隔符 ...