Line belt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2927 Accepted Submission(s): 1119
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
题意:两条线段AB和CD。起点在A,终点在D。在线段AB内的速度为p,在线段CD内的速度为q,在其它区域的速度为R。求从起点到终点的最短时间。
题解:先三分在AB线段的终点,在三分CD线段的起点。
代码如下:
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<string>
#include<stack>
#include<math.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#define nn 110000
#define inff 0x7fffffff
#define eps 1e-8
#define mod 1000000007
typedef long long LL;
const LL inf64=LL(inff)*inff;
using namespace std;
struct point
{
double x,y;
point(double x=0,double y=0):x(x),y(y){}
};
point operator + (point A,point B)
{
return point(A.x+B.x,A.y+B.y);
}
point operator/(point A,double B)
{
return point(A.x/B,A.y/B);
}
point operator - (point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
double dis(point A,point B)
{
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
point A,B,C,D;
double p,q,r;
double check(point X,point Y)
{
return dis(A,X)/p+dis(X,Y)/r+dis(Y,D)/q;
}
double solve(point X)
{
point l=C,r=D;
point mid,mmid;
double ix,fc;
while(dis(l,r)>eps)
{
mid=l+(r-l)/3.0;
mmid=r-(r-l)/3.0;
ix=check(X,mid);
fc=check(X,mmid);
if(ix>fc)
{
l=mid;
}
else
r=mmid;
}
return check(X,l);
}
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);
point l=A,r=B;
point mid,mmid;
double ix,fc;
while(dis(l,r)>eps)
{
mid=l+(r-l)/3.0;
mmid=r-(r-l)/3.0;
ix=solve(mid),fc=solve(mmid);
if(ix>fc)
{
l=mid;
}
else
r=mmid;
}
printf("%.2lf\n",solve(l));
}
return 0;
}

527

被折叠的 条评论
为什么被折叠?



