hdu3714 三分找最值

时间:2021-10-26 01:57:21

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.

hdu3714 三分找最值

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&colon; 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 &lpar;Advanced Level&rpar; Practice 1011 World Cup Betting &lpar;20 分&rpar; (找最值)

    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. Redis教程&lpar;十三&rpar;:管线详解

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/141.html 一.请求应答协议和RTT: Redis是一种典型的基于C/ ...

  2. Apple的App Analytics统计平台你必须知道的Q&amp&semi;A整理与翻译

    Apple的App Analytics统计平台你必须知道的Q&A整理与翻译 Apple最近在iTunesConnect里最新发布了App Analytics统计平台,提供了现有友盟统计平台和自 ...

  3. n条直线最多能将一个平面分成多少部分?

    f(n)=n(n+1)/2+1 原理:第N条直线可以被前N-1条直线分为N段,对于 每1段则将平面分为两份,所以对于前 f(n)=f(n-1)+n. f(n-1)=f(n-2)+n-1 ...... ...

  4. 【转】Java编程之字符集问题研究

    发现这是对字集说得最明了的一篇文章了. 转发自:http://tomcat-oracle.iteye.com/blog/2037160 1. 概述 本文主要包括以下几个方面:编码基本知识,java,系 ...

  5. Doxygen安装使用

    Doxygen是一个 C++.C.Java.Objective-C.Python.IDL(CORBA和Microsoft flavors).Fortran.VHDL.PHP.C#和D语言的文檔生成器. ...

  6. 【锋利的Jquery】读书笔记三

    DOM操作 三个方面;DOM core    html-dom  css-dom 注意点: 删除事件中 三种删除节点的方法   remove   detach   empty remove不解释 de ...

  7. -webkit-overflow-scrolling

    -webkit-overflow-scrolling 属性 控制元素在移动设备上是否使用滚动回弹效果. 取值 auto    使用普通滚动, 当手指从触摸屏上移开,滚动会立即停止. touch   使 ...

  8. Android之应用市场排行榜、上架、首发

    文章大纲 一.应用市场排行榜介绍二.应用市场上架介绍三.应用市场首发介绍四.参考文档   一.应用市场排行榜介绍   iiMedia Research(艾媒咨询)权威发布<2017-2018中国 ...

  9. 【刷题】LOJ 6014 「网络流 24 题」最长 k 可重区间集

    题目描述 给定实直线 \(L\) 上 \(n\) 个开区间组成的集合 \(I\) ,和一个正整数 \(k\) ,试设计一个算法,从开区间集合 \(I\) 中选取出开区间集合 \(S \subseteq ...

  10. 【leetcode】solution in java——Easy4

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6415011.html 16:Invert Binary Tree 此题:以根为对称轴,反转二叉树. 思路:看到 ...