Problem Description
In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww's speed on AB is P and on CD is Q, he can move with the speed R on other area on the plane. How long must he take to travel from A to D?
Input
The first line is the case number T. For each case, there are three lines. The first line, four integers, the coordinates of A and B: Ax Ay Bx By. The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy. The third line, three integers, P Q R. 0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000 1<=P,Q,R<=10
Output
The minimum time to travel from A to D, round to two decimals.
Sample Input
1 0 0 0 100 100 0 100 100 2 2 1
Sample Output
136.60由于三分的是点的坐标,所以刚拿到题的时候思路不清晰。先在cd上找一点使从ab到这点加上这点到d的时间最小finf2(),再在ab上找一点使a到这点的时间加上find2()的结果最小#include<cstdio> #include<cmath> #define eps 1e-5 struct point { int x,y; }; int dis(point a,point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } int p,q,r; double find2(point a,point c,point d) { point l,h,mid1,mid2; double t1,t2; l=c;h=d; do { mid1.x=(l.x+h.x)/2; mid1.y=(l.y+h.y)/2; mid2.x=(mid1.x+h.x)/2; mid2.y=(mid1.y+h.y)/2; t1=dis(a,mid1)/r+dis(mid1,d)/q; t2=dis(a,mid2)/r+dis(mid2,d)/q; if(t1>t2) l=mid1; else h=mid2; }while(dis(l,h)>=eps); return t1; } double find(point a,point b,point c,point d) { point l,h,mid1,mid2; double t1,t2; l=a; h=b; do { mid1.x=(l.x+h.x)/2; mid1.y=(l.y+h.y)/2; mid2.x=(mid1.x+h.x)/2; mid2.y=(mid1.y+h.y)/2; t1=dis(a,mid1)/p+find2(mid1,c,d); t2=dis(a,mid2)/p+find2(mid2,c,d); if(t1>t2) l=mid1; else h=mid2; }while(dis(l,h)>=eps); return t1; } int main() { int T; point a,b,c,d; scanf("%d",&T); while(T--) { scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y); scanf("%lf%lf%lf%lf",&c.x,&c.y,&d.x,&d.y); scanf("%d%d%d",&p,&q,&r); printf("%.2lf\n",find(a,b,c,d)); } return 0; }