三分套三分。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define eps 1e-4 using namespace std; double x,y,v1,v2,v0; struct point { double x,y; point (double x,double y):x(x),y(y) {} point () {} }a,b,c,d; double dis(point x,point y) { return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y)); } double calc(point x) { point l=c,r=d,k1,k2; while (fabs(r.x-l.x)>eps || fabs(r.y-l.y)>eps) { k1=point(l.x+(r.x-l.x)/3,l.y+(r.y-l.y)/3); k2=point(l.x+(r.x-l.x)/3*2,l.y+(r.y-l.y)/3*2); if (dis(x,k1)/v0+dis(k1,d)/v2>dis(x,k2)/v0+dis(k2,d)/v2) l=k1;else r=k2; } return dis(x,l)/v0+dis(l,d)/v2; } int main() { scanf("%lf%lf",&x,&y);a=point(x,y); scanf("%lf%lf",&x,&y);b=point(x,y); scanf("%lf%lf",&x,&y);c=point(x,y); scanf("%lf%lf",&x,&y);d=point(x,y); scanf("%lf%lf%lf",&v1,&v2,&v0); point l=a,r=b,k1,k2; while (fabs(r.x-l.x)>eps || fabs(r.y-l.y)>eps) { k1=point(l.x+(r.x-l.x)/3,l.y+(r.y-l.y)/3); k2=point(l.x+(r.x-l.x)/3*2,l.y+(r.y-l.y)/3*2); if (calc(k1)+dis(a,k1)/v1>calc(k2)+dis(a,k2)/v1) l=k1;else r=k2; } printf("%.2lf\n",calc(l)+dis(a,l)/v1); return 0; }