三分找最值(a>0)
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const double eps=1e-7;
const int maxn=1e3+10;
int a,b,c;
double calc(double x)
{
return (double)a*x*x+b*x+c;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>a>>b>>c;
double l=-10000,r=10000;
while (r-l>eps)
{
double midl=l+(r-l)/3;
double midr=r-(r-l)/3;
if (calc(midl)-calc(midr)>eps) l=midl;//找最小,f(midr)<f(midl),答案向 r靠拢,移动l
else r=midr;//同理
}
printf("%.4lf",calc(l));
return 0;
}
/*
5 3
1 2 3 4 5
*/