您的位置:首页 > 其它

专题二 1006

2016-04-24 12:13 330 查看

一. 题目编号

1006

Line belt

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

二. 简单题意

给出两条传送带的起点到末端的坐标,其中AB为p的速度,CD为q的速度 其他地方为r的速度, 求A到D点的最短时间

三. 解题思路形成过程



利用凸性, 如图必定在AB CD上存在XY 使得A—D 用时间最短。用三分法针对AB间的某个点找出在CD段上最小的点,嵌套循环找出最小的时间。

四. 感想

仅凭脑袋空想还是挺转的, 但是看到这个图之后思路就一下子开了一样, 以后如果遇到这种类似几何的问题一定要画图思考,会事半功倍的。

五. AC代码

#include<stdio.h>
#include<math.h>
#define eps 1e-9

struct point
{
double x;
double y;
};
point A,B,C,D,M1,M2;
double P,Q,R;

double dis(point a,point b)
{
return sqrt(eps+(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double cal2(double len)
{
double d1,d2,k,t1,t2;
d1=len,d2=dis(C,D);
k=d1/d2;
M2.x=(C.x-D.x)*k+D.x;
M2.y=(C.y-D.y)*k+D.y;
t1=dis(M1,M2)/R;
t2=len/Q;
return (t1+t2);
}

double cal1(double len)
{
int i;
double d1,d2,k,t1,tx,ty;
d1=len,d2=dis(A,B);
k=d1/d2;
M1.x=(B.x-A.x)*k+A.x;
M1.y=(B.y-A.y)*k+A.y;
t1=len/P;
double left,right,mid1,mid2;
left=0,right=dis(C,D);
for(i=1;i<=100;i++)
{
mid1=(2*left+right)/3;
mid2=(left+2*right)/3;
tx=cal2(mid1);
ty=cal2(mid2);
if(tx>ty)
{
left=mid1;
}
else
{
right=mid2;
}
}
return t1+cal2(left);
}

void triple()
{
int i;
double mid1,mid2,left,right,t1,t2;
left=0,right=dis(A,B);
for(i=1;i<=100;i++)
{
mid1=(left*2+right)/3;
mid2=(left+2*right)/3;
t1=cal1(mid1);
t2=cal1(mid2);
if(t1>t2)
{
left=mid1;
}
else
{
right=mid2;
}
}
printf("%.2lf\n",cal1(left));
}

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);
triple();
}
return 0;
}


9d81
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: