zoj 4041 Chasing(三分)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4041

 

如果需要再一个抛物线的函数中找到最高点,就需要三分了。

这道题同理

 

#include
#include
#include
#include
using namespace std;
double eps=1e-8;
const int maxn=1e6+6;
double arr[maxn];
double pos[maxn];
int n;
double x1,x2,Y1,y2,k;
double getsum(double x) {
    double sum=0;
    sum=sqrt((x-Y1)*(x-Y1)+x1*x1);
    double sum1=sqrt((x-y2)*(x-y2)+x2*x2);
    return sum/sum1;
}
double triserch(double l,double r) {
    while(r-l>eps) {
        double ml=l+(r-l)/3.0;
        double mr=r-(r-l)/3.0;
        if(getsum(ml) < getsum(mr)) {
            r=mr;
        }
        else {
            l=ml;
        }
    }
    return getsum(l);
}
int main() {
    int T;
    scanf("%d",&T);
    while(T--) {
        scanf("%lf%lf%lf%lf%lf",&x1,&Y1,&x2,&y2,&k);
        if(k<1.0) {
            puts("N");
            continue;
        }
        double ans=triserch(-100000,100000);
        if(ans*k<=1.0)printf("N\n");
        else printf("Y\n");
    }
}

 

你可能感兴趣的:(三分)