三分法

· · 个人记录

\text{double} 类型


double eps=1e-12;
double fen_3(double l,double r)
{
    while(l+eps<r)
    {
        double lmid=l+(r-l)/3.0;
        double rmid=r-(r-l)/3.0;
        if(check(lmid)<check(rmid))
            l=lmid;
        else
            r=rmid;
    }
    return l;
}