社区讨论
求助 subtask 2
P1883【模板】三分 / 函数 / [ICPC 2010 Chengdu R] Error Curves参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lyiekagb
- 此快照首次捕获于
- 2024/07/12 15:54 2 年前
- 此快照最后确认于
- 2024/07/12 16:38 2 年前
rt.
精度是 1e-10 会 wa,1e-11 会 T。
代码:
CPP#include<bits/stdc++.h>
using namespace std;
int t,i,n;
double a[10009],b[10009],c[10009];
double calc(int i,double x)
{
return a[i]*x*x+b[i]*x+c[i];
}
double check(double x)
{
double ret=-1e9;
for(i=1;i<=n;i++) ret=max(ret,calc(i,x));
return ret;
}
const double eps=1e-11;
int main()
{
cout<<fixed<<setprecision(4);
cin>>t;
while(t--)
{
cin>>n;
for(i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
double l=0,r=1e9,ans=0;
while(r-l>eps)
{
// cout<<l<<" "<<r<<endl;
double mid1=l+(r-l)/3.000,mid2=r-(r-l)/3.000;
if(check(mid1)<=check(mid2)) r=mid2-eps,ans=check(mid1);
else l=mid1+eps;
}
cout<<ans<<endl;
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...