解题:3分
#include <cstdio> #include<algorithm> #include<cmath> using namespace std; #define Min_(a,b) (a<b?a:b) #define Max_(a,b) (a>b?a:b) double dis(double x1,double y1,double x2,double y2) { return sqrt( fabs(x1-x2)*fabs(x1-x2)+fabs(y1-y2)*fabs(y1-y2) ); } int main() { int T; double x1,x2,y1,y2,a,b,m,n; double tmp1,tmp2,num1,num2,min; scanf("%d",&T); while(T--) { scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&a,&b); min=dis(x1,y1,x2,y2)/a; m=Min_(x1,x2); n=Max_(x1,x2); while(m<=n) { tmp1=m+(n-m)/3.0; tmp2=m+(n-m)*2.0/3.0; num1=dis(x1,y1,tmp1,0)/a+dis(x2,y2,tmp1,0)/b; num2=dis(x1,y1,tmp2,0)/a+dis(x2,y2,tmp2,0)/b; if(num1>num2) { m=tmp1+0.001; } else { n=tmp2-0.001; } } min=Min_(num1,min); min=Min_(num2,min); printf("%.2lf\n",min); } return 0; }