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 ...
随机推荐
- Linux 报错 ifconfig command not found
1.Linux 中输入ifconfig命令报错:ifconfig command not found 有可能是没有安装ifconfig,如果没有,安装上去 2.查看是不是缺少了ifconfig,它是在 ...
- Java线程处理
Java线程处理 创建线程 继承Thread类 public class TestThread extends Thread{ public void run(){ System.out.printl ...
- 出生年 (15 分) C解法
出生年 以上是新浪微博中一奇葩贴:"我出生于1988年,直到25岁才遇到4个数字都不相同的年份."也就是说,直到2013年才达到"4个数字都不相同"的要求.本题 ...
- Iframe用法精析
String.prototype.match()中正则表达式的g标识存在的时候,函数不会捕获子表达式中的内容,不存在的时候可以. RegExp.prototype.exec()中g的存在只会影响,Re ...
- Qt中实现无边框的窗体
1 自定义窗体类继承自QWidget 2 在构造函数中设置无边框效果 setWindowFlags(Qt::FramelessWindowHint);//无边框 setAttribute(Qt::WA ...
- Linux学习笔记记录(七八)
- 2.8 补充:shell脚本执行方法
bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本 ...
- 【Codeforces 977F】Consecutive Subsequence
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设f[i]表示i作为序列的最后一个数字,最长的连续序列的长度. 用f[i]和f[i-1]+1来转移即可 [代码] import java.io ...
- WordCountPro,完结撒花
WordCountPro,完结撒花 软测第四周作业 一.概述 该项目github地址如下: https://github.com/YuQiao0303/WordCountPro 该项目需求如下: ht ...
- lua 栈最后调用的函数,用于看调试信息
lua_getinfo int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); 返回一个指定的函数或函数调用的信息. 当用于取 ...