Description
Little classmate's younger brother Xiao yesterday studied mathematics in a yuan two times function, but because of academic not fine, he one night all in the small question one yuan two times function of extremum problem, small bored cannot withstand, so, want to ask you to help get a program to deal with small. Program to complete the following tasks:
I'll give you a two-time function, the first one is:.
Set the function.
Ask you to find the minimum value on the interval, and the result holds a valid digit.
Input
The first line of the input file is an integer.
The next line, each line of real numbers, is separated by a space.
Output
Outputs a single real number that represents the minimum value on the interval.
Sample Input
2
3--2 1
2-4 2
Sample Output
0.686
HINT
Solution
This is a two-minute, three-point subject.
Two-point answer, the judgment of the intersection of the domain and whether there is overlap.
Drawing shows that it is a single-peak function. Three score, sentenced.
Pay attention to accuracy.
#include <cmath>#include<ctime>#include<stack>#include<queue>#include<cstdio>#include<vector>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>#defineEPS 1e-10#defineM 1000#defineN 100005using namespacestd;structfunc{DoubleA,b,c;} A[n];intN;DoubleL=0.0, r=1000.0, M1,m2;inlineDoubleFDoublex) { Doubleret=a[1].a*x*x+a[1].b*x+a[1].c; for(intI=2; i<=n;++i) RET=max (ret,a[i].a*x*x+a[i].b*x+a[i].c); returnret;} Inlinevoidinit () {scanf ("%d",&N); for(intI=1; i<=n;++i) scanf ("%LF%LF%LF",&a[i].a,&a[i].b,&a[i].c); while(l+eps<R) {M1= (r-l)/3.0; m2=l+m1*2.0; m1+=l; if(f (M1) >f (m2)) l=m1+EPS; ElseR=m2; } printf ("%.3lf\n", F (L));}intMain () {Freopen ("curves.in","R", stdin); Freopen ("Curves.out","W", stdout); Init (); Fclose (stdin); Fclose (stdout); return 0;}
[Daily Training]curves