当前位置:编程学习 > C/C++ >>

uva 10566 - Crossed Ladders

#include<iostream>
#include<iomanip>
#include<cmath>
#define sqr(a) ((a)*(a))
#define eps 1e-8

using namespace std;

int sig(double a)
{
    return (a>eps)-(a<-eps);
}
int main()
{
    double x,y,c;
    double l,r,mid,tmp;
    while(cin>>x>>y>>c)
    {
        if(sig(x-y)>0)
        {
            l=x;x=y;y=l;
        }
        x=sqr(x);y=sqr(y);
        l=sqrt(x-sqr(2*c));
        r=y-sqr(2*c);
        if(sig(r-x)>=0) r=x;
        r=sqrt(r);
        mid=(l+r)/2;
        while(sig(r-l)>0)
        {
            tmp=c/sqrt(y-sqr(mid))+c/sqrt(x-sqr(mid));
            if(sig(tmp-1)==0) break;
            else if(sig(tmp-1)>0) r=mid;
            else l=mid;
            mid=(l+r)/2;
        }
        cout<<fixed<<setprecision(3)<<mid<<endl;
    }
    return 0;
}

 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,