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 三分的更多相关文章

  1. UVA 1476 - Error Curves(三分法)

    UVA 1476 1476 - Error Curves 题目链接 题意:给几条下凹二次函数曲线.然后问[0,1000]全部位置中,每一个位置的值为曲线中最大值的值,问全部位置的最小值是多少 思路:三 ...

  2. 【单峰函数,三分搜索算法(Ternary_Search)】UVa 1476 - Error Curves

    Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...

  3. uva 1476 - Error Curves

    对x的坐标三分: #include<cstdio> #include<algorithm> #define maxn 10009 using namespace std; do ...

  4. UVA 5009 Error Curves

    Problem Description Josephina is a clever girl and addicted to Machine Learning recently. She pays m ...

  5. nyoj 1029/hdu 3714 Error Curves 三分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3714 懂了三分思想和F(x)函数的单调性质,这题也就是水题了 #include "stdio ...

  6. hdu 3714 Error Curves(三分)

    http://acm.hdu.edu.cn/showproblem.php?pid=3714 [题意]: 题目意思看了很久很久,简单地说就是给你n个二次函数,定义域为[0,1000], 求x在定义域中 ...

  7. UVALive 5009 Error Curves 三分

    //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include& ...

  8. LA 5009 (HDU 3714) Error Curves (三分)

    Error Curves Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu SubmitStatusPr ...

  9. hdu 3714 Error Curves(三分)

    Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

随机推荐

  1. JTCalendar

    JTCalendar是一款简易使用而且能够自己定义事件的日历.包含圈点标识的颜色等都能够自己定义.demo中还提供了转换日历模式的样例. 效果图: " style="margin: ...

  2. hdoj--3367--Pseudoforest(伪森林&&最大生成树)

    Pseudoforest Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  3. vue.js的学习之路

    因为对jquery的ajax渲染很不满,所以我就来学vue.js了 1)vue.js是什么 官方解释为:Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型 ...

  4. docker初安装的血泪史

    最近docker很火,不管是朋友圈内还是公司内聊天都离不开docker,于是对docker产生了极大的好奇心,凭着一颗程序猿的好奇心开始了docker的安装血泪史. 首先我有一台从公司退役的本本x22 ...

  5. Oracle Access和filter的区别

    在查看Oracle执行计划的时候经常会遇到Access和filter,脑容量太小,总是分不清两者的区别...稍作整理. Access:表示对应的谓词条件会影响数据的访问路径(是按照索引还是表) Fil ...

  6. Fildder 4接口测试工具Post请求方式

  7. C# 鼠标左右手切换

    using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServi ...

  8. Linux(1)---常用命令

    1.将tgz文件解压到指定目录: # tar zxvf test.tgz -C 指定目录 比如将 /lyl/test.tgz解压到 /lyl/linux 目录下 # tar zxvf /lyl/tes ...

  9. web自动化-selenium2入门讲解(mac版本)

    最近要做一个selenium2的分享,于是总结了下我用selenium2的感受,希望分享出来,可以对入门的小伙伴有一点帮助,也希望得到大佬的指教   一,环境搭建maven+selenium2+tes ...

  10. wordpress 拾遗

    wordpress 拾遗 运行环境 php mySQL Apache 集成开发环境 Appserv xampp phpstudy 文章和页面的区别 文章是发布网站主要内容的地方,比如博客的文章,商城的 ...