UVA 1476 - Error Curves(三分法)
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(三分法)的更多相关文章
- 【单峰函数,三分搜索算法(Ternary_Search)】UVa 1476 - Error Curves
Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...
- UVA - 1476 Error Curves 三分
Error Curves Josephina is a clever girl and addicted to Machi ...
- uva 1476 - Error Curves
对x的坐标三分: #include<cstdio> #include<algorithm> #define maxn 10009 using namespace std; do ...
- UVA 5009 Error Curves
Problem Description Josephina is a clever girl and addicted to Machine Learning recently. She pays m ...
- LA 5009 (HDU 3714) Error Curves (三分)
Error Curves Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu SubmitStatusPr ...
- Error Curves(2010成都现场赛题)
F - Error Curves Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descript ...
- Error Curves HDU - 3714
Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...
- hdu 3714 Error Curves(三分)
Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 3714/UVA1476 Error Curves
Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
随机推荐
- canvas一周一练 -- canvas绘制饼图(3)
运行效果: <!DOCTYPE html> <html> <head> </head> <body> <canvas id=" ...
- mysqlworkbench 执行update语句报错:You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY colum ...
- Java面试问题——线程全面详解总结
一.多线程是什么?为什么要用多线程? 介绍多线程之前要介绍线程,介绍线程则离不开进程. 首先进程 :是一个正在执行中的程序,每一个进程执行都有一个执行顺序,该顺序是一个执行路径,或者叫一个控制单元: ...
- 梦想CAD控件COM接口自定义命令
在CAD软件操作中,为方便使用者,使用自定义命令发出命令,完成CAD绘图,修改,保存等操作.点击此处下载演示实例. _DMxDrawX::RegistUserCustomCommand 向CAD控件注 ...
- 08Webpage Form
Webpage Form 表单(form)在网页中主要负责数据采集功能.一个表单有三个基本组成部分: 表单标签:这里面包含了处理表单数据所用CGI程序的URL以及数据提交到服务器的方法. 表单域:包含 ...
- Uploadify上传大文件
一丶参考地址 <script type="text/javascript"> var auth = "@(Request.Cookies[FormsAuthe ...
- 模板—splay
#include<iostream> #include<cstdio> #define cin(x) scanf("%d",&x) using na ...
- css--小白入门篇6(终)
一.相对定位 定位有三种,分别是相对定位.绝对定位.固定定位. 相对定位: 1 position:relative; 绝对定位: 1 position:absolute; 固定定位: 1 positi ...
- [Luogu] P1407 [国家集训队]稳定婚姻
题目描述 我国的离婚率连续7年上升,今年的头两季,平均每天有近5000对夫妇离婚,大城市的离婚率上升最快,有研究婚姻问题的专家认为,是与简化离婚手续有关. 25岁的姗姗和男友谈恋爱半年就结婚,结婚不到 ...
- java容器(数组和集合)内元素的排序问题
package com.janson.day20180827; import java.util.*; /** * java中容器内对象的排序可以通过Collections.sort()和Arrays ...