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++ ,