UVA 1476 1476 - Error Curves

题目链接

题意:给几条下凹二次函数曲线。然后问[0,1000]全部位置中,每一个位置的值为曲线中最大值的值,问全部位置的最小值是多少

思路:三分法,因为都是下凹函数,所以全部曲线合并起来。仍然是一个下凹函数。满足单峰。用三分求极值

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; const int N = 10005;
int t, n, ans;
struct Line {
double a, b, c;
} l[N]; double cal(double x) {
double ans = l[0].a * x * x + l[0].b * x + l[0].c;
for (int i = 1; i < n; i++)
ans = max(ans, l[i].a * x * x + l[i].b * x + l[i].c);
return ans;
} double solve() {
double l = 0, r = 1000;
while (fabs(l - r) > 1e-9) {
double ml = (2 * l + r) / 3;
double mr = (l + 2 * r) / 3;
if (cal(ml) < cal(mr)) r = mr;
else l = ml;
}
return cal(l);
} int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%lf%lf%lf", &l[i].a, &l[i].b, &l[i].c);
printf("%.4lf\n", solve());
}
return 0;
}

UVA 1476 - Error Curves(三分法)的更多相关文章

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

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

  2. UVA - 1476 Error Curves 三分

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

  3. uva 1476 - Error Curves

    对x的坐标三分: #include<cstdio> #include<algorithm> #define maxn 10009 using namespace std; do ...

  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. Error Curves(2010成都现场赛题)

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

  7. Error Curves HDU - 3714

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

  8. hdu 3714 Error Curves(三分)

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

  9. HDU 3714/UVA1476 Error Curves

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

随机推荐

  1. 【转载】自制4412底板自动进入SD卡更新模块

    转载自迅为论坛:http://www.topeetboard.com参考平台:迅为iTOP-4412开发板 问题如下:在自制的底板上,当SD卡插在板子上开机时,会自动进入Updating模式,如果SD ...

  2. java_线程类的基本功能

    Thread类是实现了Runnable接口 其方法有: start()开始:开始线程 run()跑:线程内容 currentThread()现在的线程:返回当前线程 getName():获取线程名 s ...

  3. 17Oracle Database 维护

    Oracle Database 维护 备份 还原

  4. CodeFrist基础_迁移更新数据

    一丶自动迁移 第一次启用迁移:NeGet-->Enable-Migrations public DemoDbContext() : base("name=ConncodeFirst&q ...

  5. 13jsp、javaWeb开发模式

    13jsp.javaWeb开发模式-2018/07/25 1.jsp jsp实际上就是servlet.jsp=html+java,为用户提供动态内容 不适合编写Java逻辑 2.JSP原理 翻译(生成 ...

  6. Django 缓存之配置Redis

    一.cache介绍 由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存. 缓存工作原理:缓存是将一些常用的数据保存内存或 ...

  7. 怎么提交小程序给微信?微信小程序的提交审核流程

    开发者开发好一款微信小程序后,如何将其提交给微信审核呢?今天正好有空,就整理了一下小程序的提交流程,以供大家参考.如果要发布小程序,那么你需要申请真正的小程序账号,拿到appId,才能在手机预览.及提 ...

  8. mesh topology for airfoil, wing, blade, turbo

    ref Ch. 5, Anderson, CFD the basics with applications numerical grid generation foundations and appl ...

  9. uva 1444 Knowledge for the masses

    uva 1444 Description   You are in a library equipped with bookracks that move on rails. There are ma ...

  10. 从“菜鸟”码农到“资深”架构师,我到底经历了什么?--------http://baijiahao.baidu.com/s?id=1585813883835208757&wfr=spider&for=pc

    http://baijiahao.baidu.com/s?id=1585813883835208757&wfr=spider&for=pc