题目:http://acm.hdu.edu.cn/showproblem.php?pid=3400
Time Limit: 1000MS | | Memory Limit: 32768KB | | 64bit IO Format: %I64d & %I64u |
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
分析:最初自己想到的是向量,三个主要的向量:AB上的a向量,CD上的c向量,其他区域的b向量。三者满足这样的关系:(1)|a+b+c|=|AD| (2)|a|/p+|b|/r+|c|/q=min_time. (3) 0<=|a|<=|AB| (4)0<=|c|<=|CD| (5) |b|=|AD|-|a+c| 因为是极值问题自然想到三分,可是向量怎么用长度表示?不能,只有用二维坐标,把所有的位置信息存在点里,计算距离,第三个点的位置推导全部用坐标来解决。
pt,qt都是两条线段上运动的点,pt,qt的坐标可以通过线段长度之比推导出来。最后的结果确定:每定一个pt点就对qt三分,找A--pt,pt--qt,qt--D的长度之和,pt用一次三分,qt在pt的基础上再用三分,即pt在AB上动一下,qt在CD上转悠一圈。