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
因为有两个变量所以用两个三分
用cin会tle。。。没想到会在这超时。。。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
struct point
{
double x,y;
}a,b,c,d;
double P,Q,R;
double dis(point m,point n)
{
return sqrt((m.x-n.x)*(m.x-n.x)+(m.y-n.y)*(m.y-n.y));
}
double calcd(point m)
{
double t1,t2;
point m1,m2,l=c,r=d;
do
{
m1.x=(r.x+l.x)/2;
m1.y=(r.y+l.y)/2;
m2.y=(m1.y+r.y)/2;
m2.x=(m1.x+r.x)/2;
t1=dis(d,m1)/Q+dis(m,m1)/R;
t2=dis(d,m2)/Q+dis(m,m2)/R;
if(t1>t2)
l=m1;
else
r=m2;
}while(dis(m1,m2)>=1e-4);
return t1;
}
double calab()
{
double t1,t2;
point m1,m2,l=a,r=b;
do
{
m1.x=(r.x+l.x)/2;
m1.y=(r.y+l.y)/2;
m2.y=(m1.y+r.y)/2;
m2.x=(m1.x+r.x)/2;
t1=dis(a,m1)/P+calcd(m1);
t2=dis(a,m2)/P+calcd(m2);
if(t1>t2)
l=m1;
else
r=m2;
//cout<<m1.x<<' '<<m1.y<<endl;
//cout<<m2.x<<' '<<m2.y<<endl;
}while(dis(m1,m2)>=1e-4);
return t1;
}
int main()
{
int t;
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("%lf%lf%lf",&P,&Q,&R);
double ans=calab();
printf("%.2lf
",ans);
}
return 0;
}