I couldn't figure out the beauty of programming yesterday. I looked at other people's methods... I searched for water in three minutes... I haven't written it before...
The three points have evolved from the second point... the greatest value can be found when this function is not a single peak ~~ Awesome ....
Each time not only obtain the midpoint mid = (l + r)/2 .. also take the mmid = (mid + r)/2... if the value on the mid is better than mmid... r = mmid... otherwise, l = mid...
This question is exactly the same as that of yesterday's C question... It's not good to get the original question ....
Program:
#include<iostream>#include<cmath>#include<stack>#include<queue>#include<set>#include<algorithm>#include<stdio.h>#include<string.h>#define ll long long#define oo 1000000007using namespace std; struct node{ double a,b,c;}f[10005];int n;double getdata(double x){ double m=f[1].a*x*x+f[1].b*x+f[1].c; for (int i=2;i<=n;i++) m=max(m,f[i].a*x*x+f[i].b*x+f[i].c); return m;}int main(){ int T,i; double l,r,ml,mr,dl,dr; scanf("%d",&T); while (T--) { scanf("%d",&n); for (i=1;i<=n;i++) scanf("%lf%lf%lf",&f[i].a,&f[i].b,&f[i].c); l=0.0; r=1000.0; while (r-l>1e-10) { ml=(l+r)/2; mr=(ml+r)/2; dl=getdata(ml); dr=getdata(mr); if (dl>dr) l=ml; else r=mr; } printf("%.4lf\n",getdata(r)); } return 0;}