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 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?
 
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
 
题意:给出多个二次函数的A,B,C系数,求出0到1000范围内x对应的所有二次函数的最大值的最小值。
 
解析:三分即可(貌似题目保证了x对应的函数类似二次函数)
 
代码

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iterator>
#include<stack>
using namespace std;
const int INF=1e9+;
const double eps=1e-;
const int maxn=;
int N,A[maxn],B[maxn],C[maxn];
double Cal(double mid)
{
double ret=-;
for(int i=;i<N;i++)
{
ret=max(ret,A[i]*mid*mid+B[i]*mid+C[i]);
}
return ret;
}
double solve()
{
double x=,y=,mid,midmid;
int cnt=;
while(cnt--)
{
mid=(x+y)/;
midmid=(mid+y)/;
if(Cal(mid)<Cal(midmid)) y=midmid;
else x=mid;
}
return Cal(x);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
for(int i=;i<N;i++) scanf("%d%d%d",&A[i],&B[i],&C[i]);
printf("%.4f\n",solve());
}
return ;
}


Hdu3714-Error Curves(三分)的更多相关文章

  1. UVA - 1476 Error Curves 三分

                                           Error Curves Josephina is a clever girl and addicted to Machi ...

  2. HDU-3714 Error Curves(凸函数求极值)

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

  3. hdu3714 Error Curves

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

  4. nyoj 1029/hdu 3714 Error Curves 三分

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

  5. hdu 3714 Error Curves(三分)

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

  6. UVALive 5009 Error Curves 三分

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

  7. HDU3714 Error Curves (单峰函数)

    大意: 给你n个二次函数Si(x),F(x) = max{Si(x)} 求F(x)在[0,1000]上的最小值. S(x)=ax^2+bx+c       (0<=a<=100, |b|, ...

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

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

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

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

  10. hdu 3714 Error Curves(三分)

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

随机推荐

  1. 今天弄了整整一天DCloud

    开发一个新闻移动客户端 起先用appcan.apiCloud,最后选择了DCloud: MUI文档看了n久,js代码一上来不很适应编码风格,一堆括号弄得头大: 数据库由爬虫程序将新闻页面数据爬出来: ...

  2. JAVA日期处理(Timestamp)

    要写一些与数据库连接时的日期处理,pstmt.setDate()的类型是java.sql.Date类型,这种符合规范的类型其实并没有把时分秒存进数据库,所以存取时就应该用setTimestamp()或 ...

  3. 删除ubuntu旧内核

    ubuntu的内核经常升级,而老内核并不自动卸载.时间长了,就有一大堆内核垃圾,需要我们手动去清理. 先用uname -a 查看当前内核版本: xzc@xzc-HP-ProBook-4446s:~$ ...

  4. C++刷称号——2707: 素数与要素

    Description 从键盘输入的随机整数n,如果n不是质数,然后计算n所有的因素(不含1).例如,对于16,出口2,4,8:否则输出"It is a prime number." ...

  5. git删除未跟踪文件

    # 删除 untracked files git clean -f   # 连 untracked 的目录也一起删掉 git clean -fd   # 连 gitignore 的untrack 文件 ...

  6. java基础之集合

    集合的定义,集合的应用,集合的分类,集合的遍历,集合的特性

  7. SQL获取前一天0:00:00至23:59:59数据

    一.前言 因为我公司要做财务结算前一天0:00:00至23:59:59的数据,利用到动态拼接SQL语句 我们需要明白声明DateTime 和 Date 获取的时间格式是不一样的,所以通过此计算有利于得 ...

  8. createjs基础

    <canvas id="gameView" width="400px" height="400px" style="back ...

  9. iOS RGB颜色封装

    使用类别创建 .h文件 #import <UIKit/UIKit.h> @interface UIColor (HexColor) + (UIColor *)colorWithHex:(N ...

  10. 嵌入式开发——boa服务器下的ajax与cgi通信

    博主最近在最有做一个嵌入式课程设计,要求是利用基于cortax a8的物联网实验箱做一个简单的嵌入式网页交互系统作为课程设计来验收评分.因为本身自己是学前端的,所以网页部分并不是重点,主要是和boa服 ...