1 最大值最小问题,三分。。。。竟然排第六当时。。。。。 2 #include<stdio.h> 3 4 #include<string.h> 5 #define max 10000+10 6 #define Max(x,y) (x>y?x:y) 7 #define Min(x,y) (x<y?x:y) 8 #define inf 1e-8 9 10 typedef long long LL; 11 int a[max],b[max],c[max]; 12 int t,n; 13 14 double func(int a,int b,int c,double x){ 15 return a*x*x+b*x+c; 16 } 17 18 double solve(double x){ 19 double res=func(a[0],b[0],c[0],x); 20 for(int i=1;i<n;i++){ 21 res=Max(res,func(a[i],b[i],c[i],x)); 22 } 23 return res; 24 } 25 26 int main(){ 27 scanf("%d",&t); 28 while(t--){ 29 scanf("%d",&n); 30 for(int i=0;i<n;i++){ 31 scanf("%d%d%d",&a[i],&b[i],&c[i]); 32 } 33 double left=0.0,right=1000.0; 34 while(right-left>inf){ 35 double mid=(left+right)*0.5; 36 double mmid=(left+mid)*0.5; 37 double res1=solve(mid); 38 double res2=solve(mmid); 39 if(res2-res1>inf){ 40 left=mmid; 41 } 42 else{ 43 right=mid; 44 } 45 } 46 double ans=solve(left); 47 printf("%.4lf ",ans); 48 } 49 }