call 大佬 三分姿势

 

为什么注释掉的三分方式不能过 

@大佬

题目来源:http://hihocoder.com/problemset/problem/1142?sid=1003381

貌似不是eps的问题

#include<cstdio>
#include<cmath>
#define eps 1e-4
using namespace std;
double a,b,c,x,y;
double l,r,p,mid1,mid2,k1,k2,ans1,ans2;
double f(double fx)
{
     double fy=a*fx*fx+b*fx+c;
     return sqrt((x-fx)*(x-fx)+(y-fy)*(y-fy));
}
int main()
{
    scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&x,&y);
    l=-200;r=200;
    while(r-l>eps)
    {
        //mid1=(2*l+r)/3;mid2=(l+2*r)/3;
//这种三分姿势不能过
        mid1=(l+r)/2;mid2=(mid1+r)/2;
        k1=f(mid1);k2=f(mid2);
        if(k1<=k2) r=mid2;
        else l=mid1;
    }
    printf("%.3lf",f(l));
    return 0;
}

 

posted @ 2017-03-14 19:53  TRTTG  阅读(180)  评论(0编辑  收藏  举报