1 条题解

  • 0
    @ 2023-6-21 20:13:14

    C++ :

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    #define MAXN 10010
    #define inf 0x7fffffff
    int t,n;
    int a[MAXN],b[MAXN],c[MAXN];
    inline int read(){
    	int x=0,t=1,c;
    	while(!isdigit(c=getchar())) if(c=='-') t=-1;
    	while(isdigit(c)) x=x*10+c-'0',c=getchar();
    	return x*t;
    }
    double calc(double x){
    	double maxn=-inf;
    	for(int i=1;i<=n;i++) maxn=max(maxn,a[i]*x*x+b[i]*x+c[i]);
    	return maxn;
    }
    void sanfen(){
    	double l=0,r=1000;
    	while(l+1e-10<r){
    		double lmid=l+(r-l)/3.0,rmid=r-(r-l)/3.0;
    		if(calc(lmid)<=calc(rmid)) r=rmid;
    		else l=lmid;
    	}
    	printf("%.4lf\n",calc(l));
    }
    int main(){
    	t=read();
    	while(t--){
    		n=read();
    		for(int i=1;i<=n;i++) a[i]=read(),b[i]=read(),c[i]=read();
    		sanfen();
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    1055
    时间
    1000ms
    内存
    512MiB
    难度
    10
    标签
    递交数
    2
    已通过
    2
    上传者