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]全部位置中,每一个位置的值为曲线中最大值的值,问全部位置的最小值是多少 思路:三 ...
随机推荐
- tomcat访问端口
问题描述:今天,访问服务器上的应用,tomcat服务器已经启动,确怎么都打不开:问题原因:原来有人改了端口.具体操作:进入tomcat的安装目录,进入conf文件夹下,找到server.xml文件.用 ...
- SpringBoot 上传、下载(四)
工程目录结构 完整代码: 1.pom.xml 首先当然是添加依赖,用到thymeleaf模板渲染html页面 <project xmlns="http://maven.apache.o ...
- 《Python》模块和包
一.模块 1.什么是模块: 一个模块就是一个包含了Python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1.使用Python编写的代码(. ...
- C# 表达式树学习笔记
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 学习net core的一些疑问?
所有的内容是否一定都要依赖注入? 获取配置文件的方式是否在类库是获取不到环境变量的? 老出现:InvalidOperationException: Unable to resolve service ...
- 数字签名-MD5
MD5是信息摘要的意思,报文产生摘要是唯一的(1:1),而且是单向的(通过摘要反推不出源报文) java中的java.security.MessageDigest类,参考MessageDigest的功 ...
- rabbitMq无法消费发送的q的问题
1.问题叙述: 该项目配置了10来个mq,应对新开发需求,我也加了一个mq配置,然后在本地代码当中调用,当中接受,与前面写法相似,项目上测试环境测试.发现发送了queue之后本地消费日志没有的bug. ...
- redis_key键
exists k1,判断k1是否存在,‘1’就是存在,‘0’ 就是不存在 move k3 2 --->这里就是说把k3移动到2号库. ‘1’为成功,‘0’为失败 ttl k2 --查看k2 ...
- drf 分页
分页: 1.简单的分页: 每页显示条数: page_size = api_settings.PAGE_SIZE 查询的页码数: page_query_param = "page" ...
- SQL注入之Sqli-labs系列第二十八关(过滤空格、注释符、union select)和第二十八A关
开始挑战第二十八关(Trick with SELECT & UNION) 第二十八A关(Trick with SELECT & UNION) 0x1看看源代码 (1)与27关一样,只是 ...