[FROM WOJ]#1359 Conveyor Belt

Keywords: REST

# 1359 conveyor belt

Problem surface
There are two conveyor belts on a two-dimensional plane. Each conveyor belt can be regarded as a line segment. The two conveyor belts are segment AB and segment CD respectively. The moving speed of lxhgw on AB is P, on CD is Q, and on plane is R. Now lxhgw wants to go from point A to point D. He wants to know how long it will take to walk at least.

input
The first line of input data is four integers, representing the coordinates of A and B, Ax, Ay, Bx, By, respectively.
The second line is four integers, representing the coordinates of C and D, Cx, Cy, Dx, Dy, respectively.
The third line is three integers, P, Q, R.

output
The output data is one line, representing the shortest time lxhgw moves from point A to point D, and is reserved to two decimal places after the decimal point.

sample input
0 0 0 100
100 0 100 100
2 2 1

sample output
136.60

Data range
For 100% of the data,
1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10

SOL
Obviously, the answer is to go on AB now, then to the point of CD, and then to the rest of the paragraph, so you can first three points on AB turning point, set a three-point turning point on CD, and then calculate it directly.

Code:

#include<bits/stdc++.h>
using namespace std;
#define re register
#define db double
#define il inline
struct node{double x,y;}a[4],v1,v2;
db P,Q,R;
il db mul(db x){return x*x;}
il db dis(db x1,db y1,db x2,db y2){return sqrt(mul(x1-x2)+mul(y1-y2));}
il db getdis(db l1,db l2){
	db re x1,x2,y1,y2;
	x1=a[0].x+v1.x*l1,y1=a[0].y+v1.y*l1,x2=a[3].x+v2.x*l2,y2=a[3].y+v2.y*l2;
	return dis(a[0].x,a[0].y,x1,y1)/P+dis(x1,y1,x2,y2)/R+dis(x2,y2,a[3].x,a[3].y)/Q;
}
il db get(db l1){
	db re L=0,R=1,mid1,mid2;
	while(fabs(L-R)>1e-6){
		mid1=(L+R)/2,mid2=(mid1+R)/2;
		db re k1=getdis(l1,mid1);
		db re k2=getdis(l1,mid2);
		if(k1<k2)R=mid2;else L=mid1;
	}return getdis(l1,L);
}
signed main(){
//	freopen("transporter.in","r",stdin);
//	freopen("transporter.out","w",stdout);
	for(int re i=0;i<4;i++)scanf("%lf%lf",&a[i].x,&a[i].y);
	scanf("%lf%lf%lf",&P,&Q,&R);
	v1.x=a[1].x-a[0].x,v1.y=a[1].y-a[0].y;
	v2.x=a[2].x-a[3].x,v2.y=a[2].y-a[3].y;
	db re L=0,R=1,mid1,mid2;
	while(fabs(R-L)>1e-6){
		mid1=(L+R)/2,mid2=(mid1+R)/2;
		db re k1=get(mid1);
		db re k2=get(mid2);
		if(k1<k2)R=mid2;else L=mid1;
	}printf("%.2lf",get(L));
	return 0;
}

Posted by KenGR on Sat, 12 Oct 2019 14:14:38 -0700