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 ...
随机推荐
- iOS CoreImage图片处理动态渲染(滤镜)
// // ViewController.m // CoreImageOfDong // // Created by Dong on 15/6/30. // Copyright (c) 201 ...
- VS2015--win32project配置的一些想法之在 Visual Studio 2015 中进行调试的同一时候分析性能
出处: https://msdn.microsoft.com/zh-cn/magazine/dn973013(en-us).aspx 很多开发商花了绝大多数时间获取应用程序才干正常发挥作用.更少的时间 ...
- Tool-DB:Navicat
ylbtech-Tool-DB:Navicat Navicat是一套快速.可靠并价格相当便宜的数据库管理工具,专为简化数据库的管理及降低系统管理成本而设.它的设计符合数据库管理员.开发人员及中小企业的 ...
- marge into操作
动机: 想在Oracle中用一条SQL语句直接进行Insert/Update的操作. 说明: 在进行SQL语句编写时,我们经常会遇到大量的同时进行Insert/Update的语句 ,也就是说当存在记录 ...
- ValueProvider核心的值提供系统
Model绑定的数据具有多种来源: 提交的表单 Json字符串 当前路由数据 请求地址的查询字符串 ASP.NET MVC将这种基于不同数据来源的数据提供机制实现在ValueProvider的组件中 ...
- CLR寄宿和应用程序域
Win实际上将CLR作为一个COM服务器实现在一个DLL内,即为CLR定义了标准的COM接口,并为该接口和COM服务器分配一GUID,安装FrameWork时表示CLR的COM服务器被注册到注册表内. ...
- 维基百科 MediaWiki API 解析
使用开放的 API 做一个自己的小项目,是一个很好的学习方法.但好像开放的 API 选择并不多.这里给大家多一个选择,简单介绍一下维基百科使用的 MediaWiki API. 简介 先简单介绍几个容易 ...
- px 与 pt
px:pixel,像素,屏幕上显示的最小单位,用于网页设计,直观方便: pt:point,是一个标准的长度单位,1pt=1/72英寸,用于印刷业,非常简单易用: em:即%,在CSS中,1em=100 ...
- 配置 Windows Phone 8.1通过Fiddler代理上网
第一部分,共享笔记本无线网络 前提条件: 1)笔记本一台(双网卡(有线+无线网卡) 2)网络适配器中有2张网卡: 有线连接,名称Ethernet(必须已插上有线网络,且可以上网) 无线连接,名称Wi- ...
- eclipse搭建golang for windows
用惯了eclipse,所以.... golang windows开发环境 参考文档:http://golang.org/doc/install 1.下载go安装包http://code.google. ...