您的位置:首页 > 其它

搜索(三分):HDU 3400 Line belt

2016-03-11 20:28 218 查看

Line belt

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3531 Accepted Submission(s): 1364


[align=left]Problem Description[/align]
  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?

[align=left]Input[/align]
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

[align=left]Output[/align]
The minimum time to travel from A to D, round to two decimals.

[align=left]Sample Input[/align]

1
0 0 0 100
100 0 100 100
2 2 1

[align=left]Sample Output[/align]

136.60

  

//rp++
//#include <bits/stdc++.h>

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

double eps=1e-8;

double Ax,Ay,Bx,By,Cx,Cy,Dx,Dy,P,Q,R;

double DIS(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

double Get_Time(double p1,double p2)
{
return DIS(Ax,Ay,Ax+p1*(Bx-Ax),Ay+p1*(By-Ay))*1.0/P+DIS(Dx,Dy,Dx+p2*(Cx-Dx),Dy+p2*(Cy-Dy))*1.0/Q+
DIS(Bx+(1.0-p1)*(Ax-Bx),By+(1.0-p1)*(Ay-By),Cx+(1.0-p2)*(Dx-Cx),Cy+(1.0-p2)*(Dy-Cy))*1.0/R;
}

double Get_MIN(double pos)
{
double L=0.0,R=1.0,x,y,ret;
while(R-L>=eps)
{
x=(R+2*L)/3.0;
y=(2*R+L)/3.0;

x=Get_Time(pos,x);
y=Get_Time(pos,y);

if(x-y>=eps)L=(R+2*L)/3.0;
else R=(2*R+L)/3.0;

ret=min(x,y);
}
return ret;
}

double Solve()
{
double L=0.0,R=1.0,x,y,ret;
while(R-L>=eps)
{
x=(2*L+R)/3.0;
y=(L+2*R)/3.0;

x=Get_MIN(x);
y=Get_MIN(y);

if(x-y>=eps)L=(2*L+R)/3.0;
else R=(L+2*R)/3.0;

ret=min(x,y);
}
return ret;
}

int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf",&Ax,&Ay,&Bx,&By);
scanf("%lf%lf%lf%lf",&Cx,&Cy,&Dx,&Dy);
scanf("%lf%lf%lf",&P,&Q,&R);

printf("%.2lf\n",Solve());
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: