当前位置:网站首页>UVA5009 Error Curves三分
UVA5009 Error Curves三分
2022-06-26 12:39:00 【YJEthan】
题意:求一些开口向上的凹函数的最大值的最小值(不懂就仔细读两遍)
分析:一些开口向上的凹函数的最大值的最小值仍然是凹函数
求凹凸函数的最值明显用三分。详见代码,类似二分,只不过三分在中间取两个点,函数那不懂,多画图自己就能写出来。
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int n,a[10002],b[10002],c[10002];
double m1,m2,l,r,ans;
double solve(double x)
{
int i=0;
double cont=a[0]*x*x+b[0]*x+c[0];
for(i=1;i<n;i++)
cont=max(cont,a[i]*x*x+b[i]*x+c[i]);
return cont;
}
int main()
{
int t,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d%d",&a[i],&b[i],&c[i]);
}
l=0.0;r=1000.0;
for(i=0;i<100;i++)
{
m1=(l+r)/2.0;
m2=(m1+l)/2.0;
if(solve(m1)>solve(m2))
{
r=m1;
}
else l=m2;
}
ans=(l+r)/2.0;
printf("%.4lf\n",solve(ans));
}
return 0;
}边栏推荐
猜你喜欢
微信小程序测试点总结

倍福PLC通过程序获取系统时间、本地时间、当前时区以及系统时间时区转换

A must for programmers, an artifact utools that can improve your work efficiency n times

Learning Processing Zoog

倍福EtherCAT Xml描述文件更新和下载

NoSQL mongodb - 01 introduction to NoSQL and mongodb

Research and development practice of Kwai real-time data warehouse support system

由错误<note: candidate expects 1 argument, 0 provided>引发的思考

第十章 设置结构化日志记录(二)

倍福通过CTU和TON实现时间片大小和数量的控制
随机推荐
面试题积累
使用SSH密钥对登陆服务器
别乱用 FULL_CASE 和 PARALLEL_CASE
Processing 多面体变化
.NET MAUI 性能提升
心脏滴血漏洞(CVE-2014-0160)分析与防护
倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用
倍福PLC选型--如何看电机是多圈绝对值还是单圈绝对值编码器
Stream learning record
深度解析当贝盒子B3、腾讯极光5S、小米盒子4S之间的区别
Redis learning - 02 common data types, operation commands and expiration time
复制多个excel然后命名不同的名字
Stream流学习记录
Software testing - concept
Lightflow completed the compatibility certification with "daocloud Enterprise Cloud native application cloud platform"
国标GB28181协议EasyGBS级联宇视平台,保活消息出现403该如何处理?
Typescript
Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology
单例的常用创建和使用方式
记一次phpcms9.6.3漏洞利用getshell到内网域控