LA5009 Error Curves
题意
分析
因为这些函数都可以看成下凸的,所以总函数也是下凸的(可用反证法证明)。
三分答案即可,时间复杂度\(O(100)\)
代码
#include<bits/stdc++.h>
#define rg register
#define il inline
#define co const
template<class T>il T read(){
rg T data=0,w=1;rg char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') w=-1;ch=getchar();}
while(isdigit(ch)) data=data*10+ch-'0',ch=getchar();
return data*w;
}
template<class T>il T read(rg T&x) {return x=read<T>();}
typedef long long ll;
co int N=1e4;
int n,a[N],b[N],c[N];
double F(double x){
double ans=a[0]*x*x+b[0]*x+c[0];
for(int i=1;i<n;++i) ans=std::max(ans,a[i]*x*x+b[i]*x+c[i]);
return ans;
}
int main(){
// freopen(".in","r",stdin),freopen(".out","w",stdout);
for(int T=read<int>();T--;){
read(n);
for(int i=0;i<n;++i) read(a[i]),read(b[i]),read(c[i]);
double L=0,R=1000;
for(int i=0;i<100;++i){
double m1=L+(R-L)/3,m2=R-(R-L)/3;
F(m1)<F(m2)?R=m2:L=m1;
}
printf("%.4lf\n",F(L));
}
return 0;
}
LA5009 Error Curves的更多相关文章
- Error Curves(2010成都现场赛题)
F - Error Curves Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descript ...
- 【单峰函数,三分搜索算法(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 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 ...
- 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 ...
- 三分 HDOJ 3714 Error Curves
题目传送门 /* 三分:凹(凸)函数求极值 */ #include <cstdio> #include <algorithm> #include <cstring> ...
- UVA 1476 - Error Curves(三分法)
UVA 1476 1476 - Error Curves 题目链接 题意:给几条下凹二次函数曲线.然后问[0,1000]全部位置中,每一个位置的值为曲线中最大值的值,问全部位置的最小值是多少 思路:三 ...
随机推荐
- flask项目结构(五)使用数据库
简介: 基础搭建好了,开始读写数据库吧.毕竟写的程序,也没什么高深的,就是CRUD,中文说是增删改查. 一:在数据库中增加测试数据. 在项目根目录建立init_test.py from config ...
- linux入门经验之谈
一. 选择适合自己的linux发行版 谈到linux的发行版本,太多了,可能谁也不能给出一个准确的数字,但是有一点是可以肯定的,linux正在变得越来越流行, 面对这么多的Linux 发行版,打 ...
- [PyImageSearch] Ubuntu16.04 使用OpenCV和python识别信用卡 OCR
在今天的博文中,我将演示如何使用模板匹配作为OCR的一种形式来帮助我们创建一个自动识别信用卡并从图像中提取相关信用卡数位的解决方案. 今天的博文分为三部分. 在第一部分中,我们将讨论OCR-A字体,这 ...
- UBUNTU 测试跑分
time echo "scale=5000; 4*a(1)" | bc -l -q3.14159265358979323846264338327950288419716939937 ...
- android 广播 接收短信
; i < messages.length; i++) { SmsMessage ms = SmsMessage.createFromPdu((byte[])pdus[i]); String f ...
- SharePoint Framework 把你的客户端web部件部署到经典的SharePoint页面
博客地址:http://blog.csdn.net/FoxDave 本节介绍如何把客户端web部件部署到SharePoint服务端页面.我们将继续使用之前的工程. 将HelloWorld的web部 ...
- it网站
1:http://www.importnew.com/ importnew 专注于java的论坛 2:Github是最活跃的开源代码库和版本控制平台,可以说是程序员当中知名度最高的技术社区.各 ...
- oracle 正则表达式 匹配
oracle 正则表达式 在实际应用中,想排除带有中文的字段值: select h.froomnumber from t_broker_house h where REGEXP_LIKE(froomn ...
- final文案+美工
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2476] 文案+美工: 剧情设计+题目设计+美工: 第21关: 剧情: 计算机学 ...
- L299 EST 科技英语翻译-美学取向 (下)
4. Ordering(有序美) DescriptiveExpositoryArgumentative Chinese: end focus 句尾焦点English: beginning focus ...