HDUoj 3714三分查找

it2024-10-19  18

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <vector>#include <stack>#include <queue>#include<cassert>#include<set>using namespace std ;#ifdef DeBUG#define bug assert#else#define bug //#endif#define eps 1e-10double a[10010],b[10010],c[10010];int m;inline double f(double x){ int i; double maxx=a[0]*x*x+b[0]*x+c[0]; for(i=1;i<m;i++) maxx=max(maxx,a[i]*x*x+b[i]*x+c[i]); return maxx;}int main(){ #ifdef DeBUG  freopen("C:\\Users\\Sky\\Desktop\\1.in","r",stdin); #endif  int n; scanf("%d",&n); int i,j,k; while(n--) {  scanf("%d",&m);  for(i=0;i<m;i++)  scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);  double left=0.0,right=1000.0,mid,midmid;  while(right-left>eps)  {   mid=(right+left)/2;   midmid=(mid+right)/2;   if(f(mid)>f(midmid))   {    left=mid;   }   else   {    right=midmid;   }  }  printf("%.4lf\n",f(mid));   } return 0;}

转载于:https://www.cnblogs.com/Skyxj/p/3183766.html

最新回复(0)