已知n条二次曲线si(x) = ai*x^2 + bi*x + ci(ai ≥ 0),定义F(x) = max{si(x)},求出F(x)在[0,1000]上的最小值.

链接:传送门

分析:最大值最小,我们可以利用二分来解,但是有一个更牛的方法叫:“三分法”,这个方法的应用范围是凸函数,可以看一个图像:

L和R是边界,m1,m2是三等分点,如果f(m1) < f(m2),那么最小值肯定在[l,m2]内,注意,不是[l,m1]因为如果m1在最低点右边,那么就会矛盾,同理,如果f(m2) < f(m1),那么最小值肯定在[m1,r]之间,剩下的操作和二分法基本上就是一样的了。

对于本题而言,可以看出也是一个凸函数,所以我们可以利用三分法来快速求最小值.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<map>
#include<string> using namespace std; const int maxn = ; int n, a[maxn], b[maxn], c[maxn],t; double f(double x)
{
double ans = a[] * x * x + b[] * x + c[];
for (int i = ; i <= n; i++)
ans = max(ans, a[i] * x*x + b[i] * x + c[i]);
return ans;
} int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d%d%d", &a[i], &b[i], &c[i]);
double L = 0.0, R = 1000.0; while (R - L > 0.000000001)
{
double m1 = L + (R - L) / , m2 = R - (R - L) / ;
if (f(m1) < f(m2))
R = m2;
else
L = m1;
} printf("%.4lf\n", f(L));
} return ;
}

Uva5009 Error Curves的更多相关文章

  1. Error Curves(2010成都现场赛题)

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

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

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

  3. Error Curves HDU - 3714

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

  4. UVA 5009 Error Curves

    Problem Description Josephina is a clever girl and addicted to Machine Learning recently. She pays m ...

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

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

  6. hdu 3714 Error Curves(三分)

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

  7. HDU 3714/UVA1476 Error Curves

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

  8. 三分 HDOJ 3714 Error Curves

    题目传送门 /* 三分:凹(凸)函数求极值 */ #include <cstdio> #include <algorithm> #include <cstring> ...

  9. UVA 1476 - Error Curves(三分法)

    UVA 1476 1476 - Error Curves 题目链接 题意:给几条下凹二次函数曲线.然后问[0,1000]全部位置中,每一个位置的值为曲线中最大值的值,问全部位置的最小值是多少 思路:三 ...

随机推荐

  1. C++拾遗(一)——变量和基本类型

    今天看到一个小小的算法,交换两个数却不引入中间变量,想了下没什么思路.看了答案是这样: int a, b; a = a + b; b = a - b; a = a - b; 感觉还是挺有想法的,借此也 ...

  2. 闹心的CSDN

    近来搜索技术文章时,每次来到csdn上时,显示全文就提示登陆. 唉登陆就登陆吧,记不清账号了,就用手机号获取验证码.然后更改密码.我靠,密码居然要8位以上,要有大小写字母.数字和标点符号的组合... ...

  3. RunTests.sh && RunIPhoneSecurityd.sh

    https://github.com/gh-unit/gh-unit/blob/master/Scripts/RunTests.sh     #!/bin/sh   # If we aren't ru ...

  4. _T(x) _TEXT(x) L 代表什么?

    首先  <tchar.h>中 #ifdef  _UNICODE .... #define __T(x)      L ## x  //替换 #else   /* ndef _UNICODE ...

  5. 如何修改IOS的默认字体

    The first is workaround wich is iterating over all the labels in your UIView and change the labels f ...

  6. Java学习之初识线程

    “身之主宰便是心,心之所发便是意,意之本体便是知,意之所在便是物 --摘自阳明先生语录” 1.概念 在说线程之前我们先了解关于进程的一些知识,什么是进程? 程序一旦运行就是一个独立的进程,以windo ...

  7. 按Esc键实现关闭窗体

    实现效果: 知识运用: KeyEventArgs类的KeyData属性 //获取KeyDown或KeyUp事件的键数据 public Keys KeyData {get;} 实现代码: private ...

  8. caffe修改需要的东西

    https://blog.csdn.net/zhaishengfu/article/details/51971768?locationNum=3&fps=1

  9. druid 配置WebStatFilter 网络统计以及监控

    WebStatFilter用于采集web-jdbc关联监控的数据. web.xml配置 <filter> <filter-name>DruidWebStatFilter< ...

  10. vue 动态合并单元格、并添加小计合计功能

    1.效果图 2.后台返回数据格式(平铺式) 3.后台返回数据后,整理所需要展示的属性存储到(items)数组内 var obj = { "id": curItems[i].id, ...