Error Curves

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 4928    Accepted Submission(s): 1867

Problem 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 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
 

题意:

有n个二次函数,现在要在区间[0,1000]找这些二次函数的最大值最小。

思路:

由于a大于0,所以这些函数都是开口向上的,所以对于区间内的这些二次函数的最大值构成的这个函数其实也是开口向上的,

我们要找的就是它的最小值了。可以用三分解决。

/*
* Author: sweat123
* Created Time: 2016/7/15 14:54:08
* File Name: main.cpp
*/
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<time.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1<<30
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define key_value ch[ch[root][1]][0]
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
#define eps 1e-9
using namespace std;
const int MAXN = ;
double a[MAXN],b[MAXN],c[MAXN];
int n;
double getval(double x){
double ans = -INF;
for(int i = ; i <= n; i++){
ans = max(ans,a[i] * x * x + b[i] * x + c[i]);
}
return ans;
}
double solve(){
double l,r,m,mm;
l = ,r = ;
while(r - l > eps){
//m = (l + r) / 2;
//mm = (m + r) / 2;
m = (*l + r) / ;
mm = (*r + l) / ;
if(getval(m) > getval(mm)){
l = m;
} else {
r = mm;
}
}
return getval(l);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i = ; i <= n; i++){
scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);
}
printf("%.4lf\n",solve());
}
return ;
}

hdu3714 三分找最值的更多相关文章

  1. 1548: Design road (思维题 做法:三分找极值)

    1548: Design road Submit Page    Summary    Time Limit: 2 Sec     Memory Limit: 256 Mb     Submitted ...

  2. 洛谷P3382 【模板】三分法(三分找凹凸点)

    P3382 [模板]三分法 题目描述 如题,给出一个N次函数,保证在范围[l,r]内存在一点x,使得[l,x]上单调增,[x,r]上单调减.试求出x的值. 输入输出格式 输入格式: 第一行一次包含一个 ...

  3. ZOJ3166【找环值最小】

    题意: 给你一幅图,要你找一个hotel能够满足出去回来,而且保证权值最小: 思路: 可以搜环,然后取最小权值环,拿个点: floyd方便,初始话自己到自己就是无穷,然后就枚举一下给出的hotel就好 ...

  4. hdu3714 三分

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

  5. find the most comfortable road(并差集,找差值最小的权值)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. hdu5795 A Simple Nim 求nim求法,打表找sg值规律 给定n堆石子,每堆有若干石子,两个人轮流操作,每次操作可以选择任意一堆取走任意个石子(不可以为空) 或者选择一堆,把它分成三堆,每堆不为空。求先手必胜,还是后手必胜。

    /** 题目:A Simple Nim 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5795 题意:给定n堆石子,每堆有若干石子,两个人轮流操作,每次操作 ...

  7. PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) (找最值)

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  8. Huffuman树--------找最值学会用sort和cmp

    问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, …, pn-1},用这列数构造Huffman树的过程如下: 1. ...

  9. Java实现 LeetCode 653 两数之和 IV - 输入 BST(递归,找差值)

    653. 两数之和 IV - 输入 BST 给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定的目标结果,则返回 true. 案例 1: 输入: 5 / \ 3 6 / ...

随机推荐

  1. mysql数据库乱码的问题解决

    排查原因:打断点,查看到底是在执行存数据库操作之前就已经乱码了,还是存数据库操作后乱码的. 1.前者解决方案: 在web.xml里面加上: <filter> <filter-name ...

  2. C/C++内存泄漏及检测

    参考 http://www.cnblogs.com/skynet/archive/2011/02/20/1959162.html

  3. java JSP(原创新手可进)

    一. 同等编程方式jsp与asp.net的不同 app需要做一个简单网站,和几个用户推广链接,所以涉及到web这块开发,原本昨天想直接使用asp.net来做,但是之后放弃了这个想法,因为数据访问接口都 ...

  4. pandas.DataFrame对行和列求和及添加新行和列

    导入模块: from pandas import DataFrame import pandas as pd import numpy as np 生成DataFrame数据 df = DataFra ...

  5. 使用insertBefore实现insertAdjacentHTML()

    Element.insertAdjacentHTML()方法由IE引入,并在HTML5中标准化,它将任意的HTML标记字符串插入到指定的元素“相邻”的位置. insertAdjacentHTML()有 ...

  6. [deviceone开发]-do_Webview加载JQueryMobile的示例

    一.简介 JQueryMobile是JQuery的移动版,不过它并没有像JQuery那么成功.我们只是使用JQueryMobile来展示do_Webview加载第三方js框架.适合所有开发者.二.效果 ...

  7. 全国SHP地图数据赠送

    百度搜索:GIS之家获取全国SHP图层数据的方式:收藏(ArcGIS地图全国电子地图shp格式版本GIS地图数据.GIS开发顺德政府GIS公共服务共享平台),并且截图验证,验证通过后,收下邮箱,我把下 ...

  8. Android数据库相关整理

    今天对Android中数据库相关的操作和代码做了一个整理,便于自己之后的查阅.主要内容有: 1.原生数据库写法 2.终端进sqlite的操作 3.第三方库 4.事务处理 5.权限和路径 一.原生数据库 ...

  9. 【容器云】传统金融企业的 Docker 实践

    基于 Docker 的容器云-Padis 目前市面上基于容器云的产品有很多,对于平安而言,则是基于 Docker 的 Padis 平台.所谓 Padis,全称是 PingAn Distribution ...

  10. redis参考文档

    本文为之前整理的关于redis的文档,放到博客上一份,也方便我以后查阅. redis简介 Redis是一个开源的.高性能的.基于键值对的缓存与存储系统, 通过提供多种键值数据类型来适应不同场景下的缓存 ...