F - Error Curves

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

Description

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 ifa = 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

简单三分。

可以证明,许多二次函数f取其最大即F(x)=max(f(x))依然为下凸函数,类似二次函数。

便可进行三分处理。

#include<cmath>
#include<iostream>
#include<cstdio>
#define max(x,y) ((x)<(y)?(y):(x))
double l,r,a[],b[],c[],mid,mmid;
int n;
double f(double x){
double ans=-;
for(int i=;i<=n;i++)
ans=max(ans,a[i]*x*x+b[i]*x+c[i]);
return ans;
}
int main()
{
int tt;
scanf("%d",&tt);
while(tt--){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);
l=;r=;
while(r-l>1e-){
mid=(l+r)/;
mmid=(mid+r)/;
if(f(mid)<f(mmid)) r=mmid;
else l=mid;
}
printf("%.4f\n",f(mid));
}
return ;
}

Error Curves(2010成都现场赛题)的更多相关文章

  1. Go Deeper(2010成都现场赛题)(2-sat)

    G - Go Deeper Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description ...

  2. 2011 ACM/ICPC 成都赛区(为2013/10/20成都现场赛Fighting)

    hdu 4111  Alice and Bob 博弈:http://www.cnblogs.com/XDJjy/p/3350014.html hdu 4112 Break the Chocolate ...

  3. HDU 4119Isabella's Message2011成都现场赛I题(字符串模拟)

    Isabella's Message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. hdu 4788 (2013成都现场赛 H题)

    100MB=10^5KB=10^8B 100MB=100*2^10KB=100*2^20B Sample Input2100[MB]1[B] Sample OutputCase #1: 4.63%Ca ...

  5. hdu 4465 Candy(2012 ACM-ICPC 成都现场赛)

    简单概率题,可以直接由剩余n个递推到剩余0个.现在考虑剩余x个概率为(1-p)的candy时,概率为C(2 * n - x, x) * pow(p, n + 1)  *pow(1 - p, n - x ...

  6. hdu 4465 Candy 2012 成都现场赛

    /** 对于大数的很好的应用,,缩小放大,,保持精度 **/ #include <iostream> #include <cmath> #include <algorit ...

  7. hdu 4472 Count (2012 ACM-ICPC 成都现场赛)

    递推,考虑到一n可以由i * j + 1组合出来,即第二层有j个含有i个元素的子树...然后就可以了.. #include<algorithm> #include<iostream& ...

  8. Gym101981D - 2018ACM-ICPC南京现场赛D题 Country Meow

    2018ACM-ICPC南京现场赛D题-Country Meow Problem D. Country Meow Input file: standard input Output file: sta ...

  9. 2013杭州现场赛B题-Rabbit Kingdom

    杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...

随机推荐

  1. 图片轮播插件-carouFredSel

    carouFredSel图片轮播插件基于Jquery,比较常规的轮播插件,支持滚轮及键盘左右按键,加入其它插件可实现更加复杂的特效. 主页地址:http://caroufredsel.dev7stud ...

  2. python 安装 easy_intall 和 pip python无root权限安装

    http://www.cnblogs.com/haython/p/3970426.html easy_install和pip都是用来下载安装Python一个公共资源库PyPI的相关资源包的 首先安装e ...

  3. Xcode Provisioning 路径

    ~/Library/MobileDevice/Provisioning Profiles

  4. eclipse中加放js文件报js语法错误解决办法

    1) eclipse设置         window->preference-> JavaScript -> Validator->Errors/Warnings->E ...

  5. POJ 3553 Task schedule

    原题链接:http://poj.org/problem?id=3553 这道题主要就是贪心思想吧,对于每个job,根据其截止时间 dj 从小到大排序,我们必须要尽快把dj最小的job完成掉,这样才能使 ...

  6. oracle 条件:1=1或1=0,动态添加条件

    看到where语句中有条件:where 1=1    和    1=2或1<>1 用途:     1=1:是为了添加条件时使用and并列其他条件时使用的(动态连接后续条件)     比如: ...

  7. table 与 div 固定宽高问题

    div {width:100px;height:200px;word-wrap: break-word;overflow:hidden;} 这个可以固定div的宽高,溢出内容会被剪除. table{t ...

  8. 牛顿迭代法实现平方根函数sqrt

    转自利用牛顿迭代法自己写平方根函数sqrt 给定一个正数a,不用库函数求其平方根. 设其平方根为x,则有x2=a,即x2-a=0.设函数f(x)= x2-a,则可得图示红色的函数曲线.在曲线上任取一点 ...

  9. linux源码阅读笔记 move_to_user_mode()解析

    在linux 0.11版本源代码中,在文件linux/include/asm/system.h中有一个宏定义  move_to_user_mode() 1 #define move_to_user_m ...

  10. POJ 3468 A Simple Problem with Integers(线段树区间更新,模板题,求区间和)

    #include <iostream> #include <stdio.h> #include <string.h> #define lson rt<< ...