三分 HDOJ 3714 Error Curves
/*
三分:凹(凸)函数求极值
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
const double EPS = 0.0000000001;
struct F {
double a, b, c;
}f[MAXN];
int n; double cal(double x) {
double res = -INF;
for (int i=; i<=n; ++i) {
res = max (res, f[i].a * x * x + f[i].b * x + f[i].c);
}
return res;
} int main(void) { //HDOJ 3714 Error Curves
//freopen ("HDOJ_3714.in", "r", stdin); int T; scanf ("%d", &T);
while (T--) {
scanf ("%d", &n);
for (int i=; i<=n; ++i) {
scanf ("%lf%lf%lf", &f[i].a, &f[i].b, &f[i].c);
} double l = 0.0, r = 1000.0;
for (int i=; i<=; ++i) {
double mid = (l + r) / ;
double rmid = (mid + r) / ;
if (cal (mid) < cal (rmid)) r = rmid;
else l = mid;
}
printf ("%.4f\n", cal (r));
} return ;
}
三分 HDOJ 3714 Error Curves的更多相关文章
- LA 5009 (HDU 3714) Error Curves (三分)
Error Curves Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu SubmitStatusPr ...
- hdu 3714 Error Curves(三分)
Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 3714 Error Curves
Error Curves 思路:这个题的思路和上一个题的思路一样,但是这个题目卡精度,要在计算时,卡到1e-9. #include<cstdio> #include<cstring& ...
- nyoj 1029/hdu 3714 Error Curves 三分
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3714 懂了三分思想和F(x)函数的单调性质,这题也就是水题了 #include "stdio ...
- hdu 3714 Error Curves(三分)
http://acm.hdu.edu.cn/showproblem.php?pid=3714 [题意]: 题目意思看了很久很久,简单地说就是给你n个二次函数,定义域为[0,1000], 求x在定义域中 ...
- 【单峰函数,三分搜索算法(Ternary_Search)】UVa 1476 - Error Curves
Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...
- Error Curves HDU - 3714
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 ...
- HDU 3714/UVA1476 Error Curves
Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
随机推荐
- Redis集群方案之Twemproxy+HAProxy+Keepalived+Sentinel+主从复制(待实践)
首先说明一下,Twemproxy+HAProxy+Keepalived+Sentinel+主从复制-这里提到的技术不一定全部都用上,但是全部用上之后可以达到高可用. 主从复制:实现数据一式多份的保障. ...
- 通过ICursor对Table进行操作(添加、修改、删除)
通过ICursor对Table进行操作(添加.修改.删除) 2010-03-16 16:07:37| 分类: 工作|举报|字号 订阅 来自:http://blog.163.com/liuyang12 ...
- the apple code
i know you will forget but 9 you will
- python的for else语句
Python循环中的else语句 绝大部分编程语言中都有条件判断语句,比如 if … else ,在大部语言中,else 一般只在条件判断语句中出现,与 if 语句配套出现,不过在 Python 中, ...
- 【转】Golang 关于通道 Chan 详解
原文:http://blog.csdn.net/netdxy/article/details/54564436 在用 chan 类型时,发生死锁的错误,表面上看不出什么问题 ------------- ...
- GNS3配置SecureCRT
C:\SecureCRT\SecureCRT.exe /script D:\GNS3\DyRouter.vbs /T /telnet 127.0.0.1 %p "D:\Program Fil ...
- SpringMVC学习指南-Spring框架
Spring框架主要使用依赖注入.实际上,很多牛叉的框架如Google的Guice都是使用依赖注入. ------------------------------------------------- ...
- 【Struts2五】ValueStack以及ognl表达式二(经常使用标签)
Ognl经常使用标签: 1.s:debug 假设把该标签放入到s:iterator中能够看到当前正在迭代的元素的状态 2.s:property 1.输出 ...
- Linux查看文件最后几行的命令
tail -n 20 filename说明:显示filename最后20行
- 2016/1/20 笔记 1, 包 引入 static 已经补充到类里 2,继承
继承 1,关键字 extends 2,子类自动继承父类非私有的属性和方法 也叫成员变量 成员方法 3,super代表的是父类 调用父类的方法 默认在构造函数中生成 ...