[暑假集训Day4T3]曲线
生活随笔
收集整理的這篇文章主要介紹了
[暑假集训Day4T3]曲线
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
三分模板。
三分法求單峰函數最優值,之后每次取所有二次函數最優值即可
#pragma GCC optimize(3,"Ofast","inline") #include<iostream> #include<cstdio> #define N 100005 #define eps 1e-9 using namespace std; int read() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}return x*f; } int t,n; double ans,a[N],b[N],c[N]; double check(double x) {double r=-21374404;for(int i=1;i<=n;i++){r=max(r,double(a[i]*x*x+b[i]*x+c[i]));}return r; } signed main() {//freopen("1.in","r",stdin);t=read();while(t--){n=read();for(int i=1;i<=n;i++){a[i]=read();b[i]=read();c[i]=read();}double l=0,r=1000,lmid,rmid;while(l+eps<r){rmid=r-(r-l)/3.0;lmid=l+(r-l)/3.0;if(check(lmid)<=check(rmid))r=rmid;else l=lmid;}printf("%.4lf\n",check(l));}return 0; }
轉載于:https://www.cnblogs.com/szmssf/p/11180896.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的[暑假集训Day4T3]曲线的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pthread vs openMP之我见
- 下一篇: 中国农用地包括哪些地类(我国哪些地属于农