一共六种情况。手算即可。
#include<cstdio> #include<cstring> #include<cmath> int T; double a,b,c,d,x; double ans; int main() { scanf("%d",&T); while(T--) { scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&x); double h=sqrt(c*c-x*x*c*c/(a*a)); double p=x*c/a; double tmp=a*d; if(x<=h) { double m=a*a/sqrt(a*a-x*x); double s1=m*x/2; double s2=a*c-m*x; double s3=m*x/2; if(tmp<=s1) ans=sqrt(tmp/s1)*x; else if(tmp<=s1+s2) ans=(tmp-s1+m*x)/m; else ans=x+h-sqrt((a*c-tmp)/s1)*x; } else { double m=c*c/p; double s1=m*h/2; double s2=a*c-m*h; double s3=m*h/2; if(tmp<=s1) ans=sqrt(tmp/s1)*h; else if(tmp<=s1+s2) ans=(tmp-s1+m*h)/m; else ans=h+x-sqrt((a*c-tmp)/s1)*h; } printf("%.2lf ",ans); } return 0; }