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. 旋的X-Di

    旋的X-Di | 氪加 旋的X-Di

  2. 用java流方式判断文件类型

    这个方法只能在有限的范围内有效.并不是万金油 比如 图片类型判断,音频文件格式判断,视频文件格式判断等这种肯定是2进制且专业性很强的文件类型判断. 下面给出完整版代码 首先是文件类型枚取 packag ...

  3. poj 2010 Moo University - Financial Aid(优先队列(最小堆)+ 贪心 + 枚举)

    Description Bessie noted that although humans have many universities they can attend, cows have none ...

  4. hdu 2817 A sequence of numbers(快速幂)

    Problem Description Xinlv wrote some sequences on the paper a long time ago, they might be arithmeti ...

  5. 【Linux】linux经常使用基本命令

    Linux中很多经常使用命令是必须掌握的,这里将我学linux入门时学的一些经常使用的基本命令分享给大家一下,希望能够帮助你们. 这个是我将鸟哥书上的进行了一下整理的,希望不要涉及到版权问题. 1.显 ...

  6. Hacker(19)----检测Windows系统漏洞

    想完全掌握Windows中存在的漏洞需要使用专业的漏洞扫描软件.目前常用的有MBSA(MircosoftBaselineSecurityAnalyzer).360安全卫士等. 一.使用MBSA检测系统 ...

  7. ado.net数据库操作(1)

    这些都是网上搜索到的,我把他放在自己的博客里,作为笔记 1.1创建数据库连接(sqlserver) <%@ Import Namespace="System.Data" %& ...

  8. Js字面变量,定义问题

    Js字面变量.浏览器的版本问题:

  9. PowerDesigner与UML建模应用

    一.   PD简介 PowerDesigner 是一个集所有现代建模技术于一身的完整工具,它集成了强有力的业务建模技术.传统的数据库分析和实现,以及UML对象建模.通过了元数据的管理.冲突分析和真正的 ...

  10. 最小生成树prim算法———模板

    codevs.cn 最优布线问题 #include<cstdio>#include<cstring> bool u[101]; int g[101][101],minn[101 ...