Line belt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1865 Accepted Submission(s): 704
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?
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
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
Author
lxhgww&&momodi
Source
题目大意:
给出两条传送带的起点到末端的坐标,其中ab为p的速度,cd为q的速度 其他地方为r的速度
求a到d点的最短时间
分析:
典型的三分法,先三分第一条线段,找到一个点,然后根据这个点再三分第二条线段即可
ab传送带要有一个间断点mid1, a<mid1<b(从此点跳出ab这条线)同理cd有个间断mid2,路线是a-->mid1-->mid2-->d;
双向三分过程:
默认 mid1=b
1.由ab对cd取三分,得到mid2点,返回时间t1
具体为:a到mid1,mid1到cd之间的L点和R点的最小值点mid(做三分),mid到d点,得到三分过 程的最小t1 将mid点赋值给mid2点
2.由cd对ab求三分确定mid1点,返回时间t2
由于此时的d到mid2的时间固定,此时只要三分规划出a到mid,mid到mid2的最小值,将mid的值付给mid1
3.重复1和2直到|t1-t2|无穷小为止
我的代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#define eps 1e-15
using namespace std;
struct point
{
double x,y;
};
point A,B,C,D;
double P,Q,R;
int sgn(double a)
{
return (a>eps)-(a<-eps);
}
double dist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double calcu_lin(point a,point b,point c,point d)
{
return dist(a,b)/P+dist(b,c)/R+dist(c,d)/Q ;
}
point MID(point a,point b)
{
point c;
c.x=(a.x+b.x)*0.5;
c.y=(a.y+b.y)*0.5;
return c;
}
double sanfen1(point a,point b,point c,point d,point &mid)
{
point mid1,midmid;
point l,rr;l=c;rr=d;
double t1,t2;
do
{
mid1=MID(l,rr);
midmid=MID(mid1,rr);
t1=calcu_lin(a,b,mid1,d);
t2=calcu_lin(a,b,midmid,d);
if(t1<t2)
rr=midmid;
else
l=mid1;
}
while(sgn(t1-t2)!=0);
mid=mid1;
return t1;
}
double sanfen2(point d,point c,point b,point a,point &mid)
{
point mid1,midmid;
point l,rr;l=a;rr=b;
double t1,t2;
do
{
mid1=MID(l,rr);
midmid=MID(mid1,rr);
t1=calcu_lin(a,mid1,c,d);
t2=calcu_lin(a,midmid,c,d);
if(t1<t2)
rr=midmid;
else
l=mid1;
}
while(sgn(t1-t2)!=0);
mid=mid1;
return t1;
}
void work()
{
double t1,t2;point mid1,mid2;
mid1.x=B.x;mid1.y=B.y;
do
{
//printf("okok\n");
t1=sanfen1(A,mid1,C,D,mid2);
t2=sanfen2(D,mid2,B,A,mid1);
}
while(sgn(t1-t2)!=0);
printf("%.2lf\n",t1);
}
int main()
{
int t;
double ff;
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);
work();
}
return 0;
}