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]全部位置中,每一个位置的值为曲线中最大值的值,问全部位置的最小值是多少 思路:三 ...
随机推荐
- Struts2的基础知识
Struts2属于MVC框架 Struts2的优点: 1.侵入性低 2.提供了拦截器,可以利用拦截器进行AOP编程 3.提供了类型转换器 4.支持多种表示层技术:jsp,freeMarker,Vele ...
- 每天CSS学习之caption-side
caption-side是CSS2的属性,其作用是规定标题的位置在表格的上面还是下面. 1.top:默认值,将表格标题定位在表格之上.如下例子: caption{ caption-side:top; ...
- gc图波峰波谷一直上升问题
垃圾回收曲线,波峰和波谷一直上升.正常是波峰波谷在同一水平线上,可以想象如果程序继续运行下去,老年代内存回收后也不断上升,当达到老年代满了的时候,就会报内存溢出错误. 用jmap -histo pid ...
- minidebug学习分析 01 基本框架
0x01 基本框架 基本框架就是CreateProcess启动目标程序,再通过调试事件DEBUG_EVENT在调试循环中监控程序的行为. (1)CreatProcess BOOL CreateP ...
- Centos7配置NFS
centos7配置nfs yum -y install nfs-utils rpcbind 设置服务开机启动: systemctl enable rpcbind systemctl enable nf ...
- 传统应用迁移到kubernetes(Hadoop YARN)
spark-on-yarn-with-kubernetes 该例子仅用来说明具体的步骤划分和复杂性,在生产环境应用还有待验证,请谨慎使用. 过程中可能用到的概念和术语初步整理如下: 整个迁移过程分为如 ...
- 100Mbps和100MB/s
作为毕业2年计算机专业的学生,现在才知道100Mbps和100MB/s的概念,实在是渣. Mbps=Mbit/s即兆比特每秒.Million bits per second的缩写传输速率是指设备的的数 ...
- 2019.3.5 L261 Are All Our Organs Vital?
Medicine has not always shown a lot of respect for the human body. Just think about the ghoulish dis ...
- TensorFlow函数:tf.ones_like
tf.ones_like 函数 ones_like( tensor, dtype=None, name=None, optimize=True ) 定义在:tensorflow/python/ops/ ...
- 解决 java.lang.ClassNotFoundException: javax.servlet.ServletContext报错
原因:tomcat找不到servlet,即缺少了servlet-api.jar包 解决方法: 我的项目是用maven搭建的 在pom.xml中加入依赖 <dependency> <g ...